Chapter 4: Shell Builtin Commands

45

a shell function. The -a option means each name refers to an indexed array variable; the -A option means each name refers to an associative array variable.

If both options are supplied, -A takes precedence. If no name arguments are given, or if the -p option is supplied, a list of all readonly names is printed.

The other options may be used to restrict the output to a subset of the set of readonly names. The -p option causes output to be displayed in a format that may be reused as input. If a variable name is followed by =value, the value of the variable is set to value. The return status is zero unless an invalid option is supplied, one of the name arguments is not a valid shell variable or function name, or the -f option is supplied with a name that is not a shell function. return return [n]

Cause a shell function to stop executing and return the value n to its caller.

If n is not supplied, the return value is the exit status of the last command executed in the function. return may also be used to terminate execution of a script being executed with the . (source) builtin, returning either n or the exit status of the last command executed within the script as the exit status of the script. If n is supplied, the return value is its least significant 8 bits.

Any command associated with the RETURN trap is executed before execution resumes after the function or script. The return status is non-zero if return is supplied a non-numeric argument or is used outside a function and not during the execution of a script by . or source. shift shift [n]

Shift the positional parameters to the left by n. The positional parameters from n+1 . . . $# are renamed to $1 . . . $#-n. Parameters represented by the numbers $# to $#-n+1 are unset. n must be a non-negative number less than or equal to $#. If n is zero or greater than $#, the positional parameters are not changed. If n is not supplied, it is assumed to be 1. The return status is zero unless n is greater than $# or less than zero, non-zero otherwise. test

[ test expr

Evaluate a conditional express ion expr and return a status of 0 (true) or 1

(false). Each operator and operand must be a separate argument. Expressions are composed of the primaries described below in Section 6.4 [Bash Conditional

Expressions], page 85. test does not accept any options, nor does it accept and ignore an argument of -- as signifying the end of options.

When the [ form is used, the last argument to the command must be a ].

Expressions may be combined using the following operators, listed in decreasing order of precedence. The evaluation depends on the number of arguments; see below. Operator precedence is used when there are five or more arguments.

! expr

True if expr is false.