Unix: built-in shell variables
September 29, 2008 23:03:40 Last update: September 29, 2008 23:04:08
Variables set automatically by shell:
Variables set automatically by Korn shell:
| Variable | Description |
|---|---|
| $# | 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. |
| $0 | First word; that is, command name. |
| $n | Individual 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:
| Variable | Description |
|---|---|
| ERRNO | Error number of last system call that failed. |
| LINENO | Current line number within the script or function. |
| OLDPWD | Previous working directory (set by cd). |
| OPTARG | Name of last option processed by getopts. |
| OPTIND | Numerical index of OPTARG. |
| PPID | Process number of this shell's parent. |
| PWD | Current working directory (set by cd). |
| RANDOM[=n] | Generate a new random number with each reference; start with integer n, if given. |
| REPLY | Default 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. |