work in progress…
Nearly everything in Bash grammar can be broken down to a so-called "simple command". That's why the only thing Bash has to finally 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):
WORD=WORD= in each variable assignment undergoes tilde expansion, parameter expansion, command substitution, arithmetic expansion, and quote removal before being assigned to the variable.If no command name results after expansion:
> FILE without any command will be performed: the FILE will be created!Otherwise, if a command name results:
The behaviour regarding the variable assignment errors can be tested:
This one completely exits the script
#!/bin/sh # This shell runs in POSIX mode! echo PRE # The following is an assignment error, since there can be no digit '9' # for a number with the base '8'! foo=$[8#9] echo POST
This one only terminates the enclosing compound command (the { …; }):
#!/bin/bash
# This shell runs in native Bash-mode!
echo PRE
# The following is an assignment error!
# The "echo TEST" won't be executed, since the { ...; } is terminated
{ foo=$[8#9]; echo TEST; }
echo POST
If a already parsed simple command contains no slashes, the shell attempts to locate and execute it:
PATH
Since Bash Version 4, whenever a command search fails, the shell executes a shell function named command_not_found_handle() providing the commandline in question as arguments. This can be used to provide user-friendly messages or install software packages etc… Since this function runs, naturally, in a separate execution environment, you can't really influence the main shell with it (changing directory, setting variables, …).
to be continued
Discussion