
636
|
Chapter 6: The Bash Shell and Korn Shell
This is the Title of the Book, eMatter Edition
Copyright © 2006 O’Reilly & Associates, Inc. All rights reserved.
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 $S 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.
Bash and the Korn shell automatically set these additional variables.
ksh93 automatically sets these additional variables. Variables whose names
contain “.” must be enclosed in braces when referenced—e.g., ${.sh.edchar}.
Variable Meaning
$# 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.
$0 First word; that is, command name. This will have the full pathname if it was found via a PATH
search.
$n 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 ${n}.
$*, $@ All arguments on command line ($1 $2 …).
"$*" All arguments on command ...