Predefined special parameters in the Korn shell or POSIX shell

Some parameters are set automatically by the Korn shell or POSIX shell.

The following parameters are automatically set by the shell:


Item Description
@ Expands the positional parameters, beginning with $1. Each parameter is separated by a space.

If you place " around $@, the shell considers each positional parameter a separate string. If no positional parameters exist, the shell expands the statement to an unquoted null string.

* Expands the positional parameters, beginning with $1. The shell separates each parameter with the first character of the IFS parameter value.

If you place " around $*, the shell includes the positional parameter values in double quotation marks. Each value is separated by the first character of the IFS parameter.

# Specifies the number (in decimals) of positional parameters passed to the shell, not counting the name of the shell procedure itself. The $# parameter thus yields the number of the highest-numbered positional parameter that is set. One of the primary uses of this parameter is to check for the presence of the required number of arguments.
- Supplies flags to the shell on invocation or with the set command.
? Specifies the exit value of the last command executed. Its value is a decimal string. Most commands return 0 to indicate successful completion. The shell itself returns the current value of the $? parameter as its exit value.
$ Identifies the process number of this shell. Because process numbers are unique among all existing processes, this string of up to 5 digits is often used to generate unique names for temporary files.
The following example illustrates the recommended practice of creating temporary files in a directory used only for that purpose:
temp=$HOME/temp/$$
ls >$temp
.
.
.
rm $temp
! Specifies the process number of the most recent background command invoked.
zero (0) Expands to the name of the shell or shell script.