-->

Previous | Table of Contents | Next

Page 13

An OR list has the form


command command2

command2 is executed if, and only if, command returns a non_zero exit status. The return status of AND and OR lists is the exit status of the last command executed in the list.

COMPOUND COMMANDS

A compound command is one of the following:


(list)

list is executed in a subshell. Variable assignments and built-in commands that affect the shell's environment do not remain in effect after the command completes. The return status is the exit status of list.


{ list; }

list is simply executed in the current shell environment. This is known as a group command. The return status is the exit status of list.


for name [ in word;] do list ; done

The list of words following in is expanded, generating a list of items. The variable name is set to each element of this list in turn, and list is executed each time. If the in word is omitted, the for command executes list once for each positional parameter that is set. (See "Parameters," later in this manual page.)


select name [ in word;] do list ; done

The list of words following in is expanded, generating a list of items. The set of expanded words is printed on the standard error, each preceded by a number. If the in word is omitted, the positional parameters are printed. (See "Parameters.") The PS3 prompt is then displayed and a line read from the standard input. If the line consists of the number corresponding to one of the displayed words, then the value of name is set to that word. If the line is empty, the words and prompt are displayed again. If EOF is read, the command completes. Any other value read causes name to be set to null. The line read is saved in the variable REPLY. The list is executed after each selection until a break or return command is executed. The exit status of select is the exit status of the last command executed in list, or zero if no commands were executed.


case word in [ pattern [ | pattern ]

A case command first expands word, and tries to match it against each pattern in turn, using the same matching rules as for pathname expansion. (See "Pathname Expansion," later in this manual page.) When a match is found, the corresponding list is executed. After the first match, no subsequent matches are attempted. The exit status is zero if no patterns are matches. Otherwise, it is the exit status of the last command executed in list.


if list then list [ elif list then list ] ... [ else list ] fi

The if list is executed. If its exit status is zero, the then list is executed. Otherwise, each elif list is executed in turn, and if its exit status is zero, the corresponding then list is executed and the command completes. Otherwise, the else list is executed, if present. The exit status is the exit status of the last command executed, or zero if no condition tested True.


while list do list done



until list do list done

The while command continuously executes the do list as long as the last command in list returns an exit status of zero. The until command is identical to the while command, except that the test is negated; the do list is executed as long as the last command in list returns a non_zero exit status. The exit status of the while and until commands is the exit status of the last do list command executed, or zero if none was executed.


[ function ] name () { list; }

This defines a function named name. The body of the function is the list of commands between { and }. This list is executed whenever name is specified as the name of a simple command. The exit status of a function is the exit status of the last command executed in the body. (See "Functions," later in this manual page.)

Page 14

COMMENTS

In a noninteractive shell, or an interactive shell in which the -o interactive_comments option to the set builtin is enabled, a word beginning with # causes that word and all remaining characters on that line to be ignored. An interactive shell without the -o interactive_comments option enabled does not allow comments.

QUOTING

Quoting is used to remove the special meaning of certain characters or words to the shell. Quoting can be used to disable special treatment for special characters, to prevent reserved words from being recognized as such, and to prevent parameter expansion.

Each of the meta characters listed earlier under "Definitions" has special meaning to the shell and must be quoted if it is to represent itself. There are three quoting mechanisms: the escape character, single quotes, and double quotes.

A nonquoted backslash (\) is the escape character. It preserves the literal value of the next character that follows, with the exception of <newline>.If a \<newline> pair appears, and the backslash is not quoted, the \<newline> is treated as a line continuation; that is, it is effectively ignored.

Enclosing characters in single quotes preserves the literal value of each character within the quotes. A single quote may not occur between single quotes, even when preceded by a backslash.

Enclosing characters in double quotes preserves the literal value of all characters within the quotes, with the exception of $, `, and \. The characters $ and ` retain their special meaning within double quotes. The backslash retains its special meaning only when followed by one of the following characters: $, `, ", \, or <newline>. A double quote may be quoted within double quotes by preceding it with a backslash.

The special parameters * and @ have special meaning when in double quotes. (See "Parameters," next.)

PARAMETERS

A parameter is an entity that stores values, somewhat like a variable in a conventional programming language. It can be a name, a number, or one of the special characters listed under "Special Parameters," following. For the shell's purposes, a variable is a parameter denoted by a name.

A parameter is set if it has been assigned a value. The null string is a valid value. Once a variable is set, it may be unset only by using the unset built-in command. (See "Shell Built-in Commands," later in this manual page.)

A variable may be assigned to by a statement of the form:


name=[value]

If value is not given, the variable is assigned the null string. All values undergo tilde expansion, parameter and variable expansion, command substitution, arithmetic expansion, and quote removal. If the variable has its _i attribute set (see declare in "Shell Built-in Commands") then value is subject to arithmetic expansion even if the $[...] syntax does not appear. Word splitting is not performed, with the exception of "$@", as explained under "Special Parameters." Pathname expansion is not performed.

POSITIONAL PARAMETERS

A positional parameter is a parameter denoted by one or more digits, other than the single digit 0. Positional parameters are assigned from the shell's arguments when it is invoked, and may be reassigned using the set built-in command. Positional parameters may not be assigned to with assignment statements. The positional parameters are temporarily replaced when a shell function is executed. (See "Functions," later in this manual page.)

When a positional parameter consisting of more than a single digit is expanded, it must be enclosed in braces. (See "Expansion," later in this manual page.)

SPECIAL PARAMETERS

The shell treats several parameters specially. These parameters may only be referenced; assignment to them is not allowed.

Previous | Table of Contents | Next