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 |
Description |
|
|
The value of variable var. |
|
|
Select word or words in position
i of var.
i can be a single number, a range
m-n, a range -n
(missing m implies 1), a range
m- (missing n
implies all remaining words), or |
|
|
The number of words in var. |
|
|
The number of arguments. |
|
|
Same as |
|
|
The number of characters in var. |
|
|
The number of characters in
|
|
|
Name of the program. |
|
|
Individual arguments on command line (positional parameters); 1 ≤ n ≤ 9. |
|
|
Same as |
|
|
All arguments on command line. |
|
|
Same as |
|
|
The last argument. |
|
|
Return 1 if var is set; 0 if var is not set. |
|
|
Return 1 if input filename is known, 0 if not. |
|
|
Process number of current shell; useful as part of a filename for creating temporary files with unique names. |
|
|
Same as |
|
|
Process ID number of last background process started by the shell. |
|
|
Text of the command line of the last command executed. |
|
|
Read a line from standard input. |
Examples
Sort the third through last arguments and save the output ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access