Unix: built-in shell variables 

Joined:
04/09/2007
Posts:
753

September 29, 2008 23:03:40    Last update: September 29, 2008 23:04:08
Variables set automatically by shell:
VariableDescription
$#Number of command-line arguments.
$-Options currently in effect (arguments supplied to sh or to set).
$?Exit value of last executed command.
$$Process number of current process.
$!Process number of last background command.
$0First word; that is, command name.
$nIndividual arguments on command line (positional parameters). The Bourne shell allows only nine parameters to be referenced directly (n = 1-9); the Korn shell allows n to be greater than 9 if specified as ${n}.
$*All arguments on command line ("$1 $2...").
$@All arguments on command line, individually quoted ("$1" "$2" ...).


Variables set automatically by Korn shell:
VariableDescription
ERRNOError number of last system call that failed.
LINENOCurrent line number within the script or function.
OLDPWDPrevious working directory (set by cd).
OPTARGName of last option processed by getopts.
OPTINDNumerical index of OPTARG.
PPIDProcess number of this shell's parent.
PWDCurrent working directory (set by cd).
RANDOM[=n]Generate a new random number with each reference; start with integer n, if given.
REPLYDefault reply used by select and read.
SECONDS[=n]Number of seconds since the shell was started, or, if n is given, number of seconds + n since the shell started.
Share |
| Comment  | Tags