The Single UNIX ® Specification, Version 2
Copyright © 1997 The Open Group
The shell is a command language interpreter. This chapter describes the syntax of that command language as it is used by the sh utility and the system() and popen() functions in the XSH specification.
The shell operates according to the following general overview of operations. The specific details are included in the cited sections of this chapter.
The shell reads its input from a file (see sh), from the -c option or from the system() and popen() functions in the XSH specification. If the first line of a file of shell commands starts with the characters #!, the results are unspecified.
The construct #! is reserved for implementations wishing to provide that extension. A portable application cannot use #! as the first line of a shell script; it might not be interpreted as a comment.
The shell breaks the input into tokens: words and operators. (See Token Recognition .)
The shell parses the input into simple commands (see Simple Commands ) and compound commands (see Compound Commands ).
The shell performs various expansions (separately) on different parts of each command, resulting in a list of pathnames and fields to be treated as a command and arguments (see Word Expansions ).
The shell performs redirection (see Redirection ) and removes redirection operators and their operands from the parameter list.
The shell executes a function (see Function Definition Command ), built-in (see Special Built-in Utilities ), executable file or script, giving the names of the arguments as positional parameters numbered 1 to n, and the name of the command (or in the case of a function within a script, the name of the script) as the positional parameter numbered 0 (see Command Search and Execution ).
The shell optionally waits for the command to complete and collects the exit status (see Exit Status for Commands ).