Nearly everything in [[syntax:basicgrammar | Bash grammar]] can be broken down to a "simple command". The only thing Bash has to expand, evaluate and execute is the simple command.
This step happens after the initial command line splitting.
The expansion of a simple command is done in four steps (interpreting the simple command **from left to right**):
- The words the parser has marked as **variable assignments** and **redirections** are saved for later processing.
* variable assignments precede the command name and have the form ''WORD=WORD''
* redirections can appear anywhere in the simple command
- The rest of the words are [[syntax:expansion:intro| expanded]]. If any words remain after expansion, the first word is taken to be the **name of the command** and the remaining words are the **arguments**.
- [[syntax:redirection | Redirections]] are performed.
- The text after the ''='' in each variable assignment undergoes [[syntax:expansion:tilde | tilde expansion]], [[syntax:pe | parameter expansion]], [[syntax:expansion:cmdsubst | command substitution]], [[syntax:expansion:arith | arithmetic expansion]], and quote removal before being assigned to the variable.
If **no command name** results after expansion:
* The variable assignments affect the **current shell** environment.
* This is what happens when you enter only a variable assignment at the command prompt.
* Assignment to readonly variables causes an error and the command exits non-zero.
* Redirections are performed, but do not affect the current shell environment.
If a parsed simple command contains no slashes, the shell attempts to locate and execute it:
* shell functions
* shell builtin commands
* check own hash table
* search along ''PATH''
As of Bash Version 4, when a command search fails, the shell executes a shell function named ''command_not_found_handle()'' using the failed command as arguments. This can be used to provide user friendly messages or install software packages etc. Since this function runs in a separate execution environment, you can't really influence the main shell with it (changing directory, setting variables).
FIXME to be continued
===== See also ====
* Internal: [[syntax:redirection | Redirection]]
* Internal: [[syntax:expansion:intro | Introduction to expansions and substitutions]]