I'm pretty sure the way a shell's top loop looks is like this
Code:
//psuedo code
read_input_line();
tokenize();
if (expandable) //for aliases and history substitutions
{
rewrite_exapandable_tokens();
}
//Compare the first token to a list of built in commands
foreach ( builtin in builtin_list ) {
if ( command_token == builtin )
{
execute->command_token( parameter_tokens );
break;
}
}
//If that didn't work try executing it as a filesystem command
try_execute_file_in_path( command_token );
//Finally just fail
signal_error();