Variable Substitution
In the following substitutions, braces ({ }
) are optional, except when needed to separate a variable name from following characters that would otherwise be considered part of the name.
Variable |
Meaning |
|
Value of variable |
|
Name of the program. |
|
Individual arguments on command line (positional parameters); 1 |
|
Number of arguments on command line. |
|
All arguments on command line. |
|
Same as $*, but contents are split into words when the variable is enclosed in double quotes. |
|
Process number of current shell; useful as part of a filename for creating temporary files with unique names. |
|
Exit status of last command (normally 0 for success). |
|
Process number of most recently issued background command. |
|
Current execution options (see the set built-in command). By default, hB for scripts and himBH for interactive shells. |
|
Initially set to name of file invoked for this shell, then set for each command to the last word of the previous command. |
Tables 5-23 through Table 5-25 show various types of operators that can be used with bash variables.
Operator |
Substitution |
${ |
If |
Purpose: Returning a default value if the variable is undefined. | |
Example: | |
${ |
If |
Get Mac OS X Tiger in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.