Built-in Shell Variables
Built-in variables are automatically set by the shell and are
typically used inside shell scripts. Built-in variables can make use
of the variable substitution patterns shown previously. Note that
the $ is not actually part of the
variable name, although the variable is always referenced this way.
The following are available in any Bourne-compatible shell:
|
|
Number of command-line arguments. |
|
|
Options currently in effect (arguments supplied on command line or to set). |
|
|
Exit value of last executed command. |
|
|
Process number of current process. |
|
|
Process number of last background command. |
|
|
First word; that is, command name. This will have the full pathname if it was found via a PATH search. |
|
|
Individual arguments on command
line (positional parameters). The Bourne shell allows only
nine parameters to be referenced directly
(n = 1–9); Bash and the Korn shell
allow n to be greater than 9 if
specified as |
|
|
All arguments on command line
( |
|
|
All arguments on command line as
one string ( |
|
|
All arguments on command line,
individually quoted ( |
Bash and the Korn shell automatically set these additional variables:
|
|
Temporary variable; initialized to pathname of script or program being executed. Later, stores the last argument of previous command. Also stores name of matching MAIL file during mail checks. ... |
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