5 Shell Variables
This chapter describes the shell variables that Bash uses. Bash automatically assigns default values to a number of variables.
5.1 Bourne Shell Variables
Bash uses certain shell variables in the same way as the Bourne shell. In some cases, Bash assigns a default value to the variable.
CDPATH
A colon-separated list of directories used as a search path for the cd builtin command.
HOME
The current user’s home directory; the default for the cd builtin command. The value of this variable is also used by tilde expansion (see Section 3.5.2 [Tilde
Expansion], page 22).
IFS
A list of characters that separate fields; used when the shell splits words as part of expansion.
If this parameter is set to a filename or directory name and the MAILPATH variable is not set, Bash informs the user of the arrival of mail in the specified file or Maildir-format directory.
MAILPATH
A colon-separated list of filenames which the shell periodically checks for new mail. Each list entry can specify the message that is printed when new mail arrives in the mail file by separating the filename from the message with a ‘?’.
When used in the text of the message, $_ expands to the name of the current mail file.
OPTARG
The value of the last option argument processed by the getopts builtin.
OPTIND
The index of the last option argument processed by the getopts builtin.
PATH
A colon-separated list of directories in which the shell looks for commands. A zero-length (null) directory name in the value of PATH indicates the current directory. A null directory name may appear as two adjacent colons, or as an initial or trailing colon.
PS1
The primary prompt string. The default value is ‘\s-\v\$ ’. See Section 6.9
[Controlling the Prompt], page 92, for the complete list of escape sequences that are expanded before PS1 is displayed.
PS2
The secondary prompt string. The default value is ‘> ’.
5.2 Bash Variables
These variables are set or used by Bash, but other shells do not normally treat them specially.
A few variables used by Bash are described in different chapters: variables for controlling the job control facilities (see Section 7.3 [Job Control Variables], page 100).
BASH
The full pathname used to execute the current instance of Bash.