Special Parameters

What about positional parameter 0? Actually, 0 is a shell special parameter, and there are an additional seven of these that we haven’t covered yet. We’ve already talked about the #, @, and * special parameters, but we also have:

Exit Status (?)

The exit status ? special parameter expands to the exit status of the most recently executed command. The exit status of a command can range from 0 to 255 inclusive, where the value zero (0) is reserved for a successful exit, while any non-zero value indicates failure. This parameter is initially set to 0.

Shell Options (-)

The shell options - special parameter expands to the current option flags of the shell. These are set when the shell is invoked, and several options can also be modified by the set builtin utility. See SET(1P) for a description of the shell option flags. Most shells support additional features and associated option flags not listed in the POSIX standards.

Process ID ($)

The process ID $ special parameter expands to the process ID of the shell itself. In subshells, it expands to the process ID of the parent shell, even if the subshell is implemented as a separate child process.

Background Process ID (!)

The background process ID ! special parameter expands to the process ID of the job most recently placed in the background, whether with the & control operator or with the bg builtin utility. This parameter is initially unset.

Program Name (0)

The program name 0 special parameter expands to an implementation-defined name of the shell program or the name of the current script file if the shell is invoked with a script argument. SH(1P) describes the different values that 0 has in different situations.