Built-in Shell Variables

Variable Chapter Meaning
# Number of arguments given to current process.
- Options given to shell on invocation.
? Exit status of previous command.
$ Process ID of shell process.
_ Last argument to previous command.
! Process ID of last background command.
CDPATH List of directories for cd command to search.
COLUMNS Width of display in columns (for editing modes and select).
EDITOR Used to set editing mode; also used by mail and other programs.
ERRNO A Error number of last system call that failed.
ENV Name of file to run as environment file when shell is invoked.
FCEDIT Default editor for fc command.
FPATH Search path for autoloaded functions.
IFS Internal field separator: list of characters that act as word separators. Normally set to SPACE, TAB, and NEWLINE.
HISTFILE Name of command history file.
HISTSIZE Number of lines kept in history file.
HOME Home (login) directory.
LINENO Number of line in script or function that just ran.
LINES Height of display in lines (for select command).
MAIL Name of file to check for new mail.
MAILCHECK How often (in seconds) to check for new mail.
MAILPATH List of file names to check for new mail, if MAIL is not set.
OLDPWD Previous working directory.
OPTARG Argument to option being processed by getopts.
OPTIND Number of first argument after options.
PATH Search path for commands.
PS1 Primary command prompt string.
PS2 Prompt string for line continuations.
PS3 Prompt string for select command.
PS4 Prompt string for xtrace option.
PPID Process ID of parent process.
PWD Current working directory.
RANDOM Random number between 0 and 32767 (2-1).
REPLY User's response to select command; result of read command if no variable names given.
SECONDS Number of seconds since shell was invoked.
SHELL Full pathname of shell.
TMOUT If set to a positive integer, number of seconds between commands after which shell automatically terminates.
VISUAL Used to set editing mode.