Go to the first, previous, next, last section, table of contents.
The words in a
simple command
are subjected to a number of substitutions, described later, but
eventually becomes simply a list of assignment words, normal words,
and I/O words.
If all the I/O redirection required by the I/O words is successfully
arranged, the shell attempts to execute the command. What is actually
done is determined largely by the first of the simple words in the
command body.
If this word contains any quoted characters, then only the final option - that
of finding an executable file - is attempted, otherwise each of the
following is tried in turn.
-
If the first word is the name of an
alias
or
function
the a new local copy of the ARGV variable is created and assigned all
the normal words in the command, the assignment words are used to
create local exported variables, and the commands stored for that
alias or function are executed.
While an alias is being executed, that alias is temporarily disabled thus
disabling recursion.
Functions are not so inhibited and can be recursive.
-
If the first word is the name of a built in command that is not hidden,
that command is performed by the shell. Any assignment words are
ignored (I think).
-
Finally, the shell looks for an executable file with the same name as
the first word, which contains a program to be run.
If the first word starts with a slash or one or two dots followed by a
slash, the word is taken to be a path name and a file with that name must
exist.
If the first word does not start like this, each directory named in the the
variable
PATH
(which should be a colon separated list of directory names) is searched to see
if it contains an executable file with this name.
This procedure can be modified by the value assigned to the
WHICH
variable.
If no such file is found the shell gives an error message and aborts the
command. Otherwise, the shell attempts to execute the program contained in the
file passing it the remainder of the words as arguments.
If this fails, the shell assumes that that file contains a shell script and
runs the program named in the shell variable
SHELL
passing it the name of the file and the remainder of the words as arguments.
When a command terminates, it returns an exit-value to the shell which is
usually used to indicate success or failure.
This value is a positive integer less than 256 where a value of 0 indicates
success and any other value indicates failure, the actual number depends on the
program and the reason for failure.
This number is made available through the $? parameter.
Alternately, if a program terminates because it received a signal, the $?
parameter is set to 1000 plus the signal number.
This value is also used by the
if
and
while
commands as well as the
&&
and
||
command separators to control the execution of subsequent commands.
Go to the first, previous, next, last section, table of contents.