-->

Previous | Table of Contents | Next

Page 12

DEFINITIONS

blank A space or tab.
word A sequence of characters considered as a single unit by the shell. Also known as a token.
name A word consisting only of alphanumeric characters and underscores and beginning with an alphabetic character or an underscore. Also referred to as an identifier.
meta character A character that, when unquoted, separates words. One of the following:
|, &, ;, (, ), <, >, space, tab
control operator A token that performs a control function. It is one of the following symbols:
||, &, &&, ;, ;;, (, ), |, <newline>

RESERVED WORDS

Reserved words are words that have a special meaning to the shell. The following words are recognized as reserved when unquoted and either the first word of a simple command (see "Shell Grammar," next) or the third word of a case or for command:


! case  do done elif else esac fi for function if in select then until while { }

SHELL GRAMMAR

SIMPLE COMMANDS

A simple command is a sequence of optional variable assignments followed by words and redirections separated by blank and terminated by a control operator. The first word specifies the command to be executed. The remaining words are passed as arguments to the invoked command.

The return value of a simple command is its exit status, or 128+n if the command is terminated by signal n.

PIPELINES

A pipeline is a sequence of one or more commands separated by the character |. The format for a pipeline is


 [!]command [ | command2 ... ]

The standard output of command is connected to the standard input of command2. This connection is performed before any redirections specified by the command. (See the "Redirection" section, later in this manual page.)

If the reserved word ! precedes a pipeline, the exit status of that pipeline is the logical NOT of the exit status of the last command. Otherwise, the status of the pipeline is the exit status of the last command. The shell waits for all commands in the pipeline to terminate before returning a value.

Each command in a pipeline is executed as a separate process (that is, in a subshell).

LISTS

A list is a sequence of one or more pipelines separated by one of these operators: ;, &, &&, or ||, and terminated by one of these: ;, &, or <newline>.

Of these list operators, && and || have equal precedence, followed by ; and &, which have equal precedence.

If a command is terminated by the control operator &, the shell executes the command in the background in a subshell. The shell does not wait for the command to finish, and the return status is 0. Commands separated by a ; are executed sequentially; the shell waits for each command to terminate in turn. The return status is the exit status of the last command executed.

The control operators && and || denote AND lists and OR lists, respectively. An AND list has the form:


command && command2

command2 is executed if, and only if, command returns an exit status of Zero.

Previous | Table of Contents | Next