|
Shell Variables
Up
Next
Previous
Shell Variables
The following variables are set by the shell:
-
PPID
-
The process ID of the shell's parent. This variable is readonly.
-
PWD
-
The current working directory as set by the
cd
command.
-
OLDPWD
-
The previous working directory as set by the
cd
command.
-
REPLY
-
Set to the line of input read by the
read
builtin command when no arguments are supplied.
-
UID
-
Expands to the user ID of the current user, initialized at shell startup.
This variable is readonly.
-
EUID
-
Expands to the effective user ID of the current user, initialized at
shell startup. This variable is readonly.
-
GROUPS
-
An array variable containing the list of groups of which the current
user is a member.
Assignments to
.SM
GROUPS
have no effect and are silently discarded.
If
.SM
GROUPS
is unset, it loses its special properties, even if it is
subsequently reset.
-
BASH
-
Expands to the full file name used to invoke this instance of
.BR bash .
-
BASH_VERSION
-
Expands to a string describing the version of this instance of
.BR bash .
-
BASH_VERSINFO
-
A readonly array variable whose members hold version information for
this instance of
.BR bash .
The values assigned to the array members are as follows:
.sp .5
-
BASH_VERSINFO[0\fP]
-
The major version number (the release\fP).
-
BASH_VERSINFO[1\fP]
-
The minor version number (the version\fP).
-
BASH_VERSINFO[2\fP]
-
The patch level.
-
BASH_VERSINFO[3\fP]
-
The build version.
-
BASH_VERSINFO[4\fP]
-
The release status (e.g., beta1\fP).
-
BASH_VERSINFO[5\fP]
-
The value of MACHTYPE\fP.
-
SHLVL
-
Incremented by one each time an instance of
bash
is started.
-
RANDOM
-
Each time this parameter is referenced, a random integer between
0 and 32767 is
generated. The sequence of random numbers may be initialized by assigning
a value to
.SM
.BR RANDOM .
If
.SM
RANDOM
is unset, it loses its special properties, even if it is
subsequently reset.
-
SECONDS
-
Each time this parameter is
referenced, the number of seconds since shell invocation is returned. If a
value is assigned to
.SM
.BR SECONDS ,
the value returned upon subsequent
references is
the number of seconds since the assignment plus the value assigned.
If
.SM
SECONDS
is unset, it loses its special properties, even if it is
subsequently reset.
-
LINENO
-
Each time this parameter is referenced, the shell substitutes
a decimal number representing the current sequential line number
(starting with 1) within a script or function. When not in a
script or function, the value substituted is not guaranteed to
be meaningful.
If
.SM
LINENO
is unset, it loses its special properties, even if it is
subsequently reset.
-
HISTCMD
-
The history number, or index in the history list, of the current
command.
If
.SM
HISTCMD
is unset, it loses its special properties, even if it is
subsequently reset.
-
FUNCNAME
-
The name of any currently-executing shell function.
This variable exists only when a shell function is executing.
Assignments to
.SM
FUNCNAME
have no effect and are silently discarded.
If
.SM
FUNCNAME
is unset, it loses its special properties, even if it is
subsequently reset.
-
DIRSTACK
-
An array variable (see
Arrays
below) containing the current contents of the directory stack.
Directories appear in the stack in the order they are displayed by the
dirs
builtin.
Assigning to members of this array variable may be used to modify
directories already in the stack, but the
pushd
and
popd
builtins must be used to add and remove directories.
Assignment to this variable will not change the current directory.
If
.SM
DIRSTACK
is unset, it loses its special properties, even if it is
subsequently reset.
-
PIPESTATUS
-
An array variable (see
Arrays
below) containing a list of exit status values from the processes
in the most-recently-executed foreground pipeline (which may
contain only a single command).
-
OPTARG
-
The value of the last option argument processed by the
getopts
builtin command (see
.SM
SHELL BUILTIN COMMANDS
below).
-
OPTIND
-
The index of the next argument to be processed by the
getopts
builtin command (see
.SM
SHELL BUILTIN COMMANDS
below).
-
HOSTNAME
-
Automatically set to the name of the current host.
-
HOSTTYPE
-
Automatically set to a string that uniquely
describes the type of machine on which
bash
is executing.
The default is system-dependent.
-
OSTYPE
-
Automatically set to a string that
describes the operating system on which
bash
is executing.
The default is system-dependent.
-
MACHTYPE
-
Automatically set to a string that fully describes the system
type on which
bash
is executing, in the standard GNU cpu-company-system\fP format.
The default is system-dependent.
-
SHELLOPTS
-
A colon-separated list of enabled shell options. Each word in
the list is a valid argument for the
-o
option to the
set
builtin command (see
.SM
"SHELL BUILTIN COMMANDS"
below). The options appearing in
.SM
SHELLOPTS
are those reported as
on
by set -o\fP.
If this variable is in the environment when
bash
starts up, each shell option in the list will be enabled before
reading any startup files.
This variable is read-only.
-
COMP_WORDS
-
An array variable (see Arrays\fP below) consisting of the individual
words in the current command line.
This variable is available only in shell functions invoked by the
programmable completion facilities (see Programmable Completion\fP
below).
-
COMP_CWORD
-
An index into ${COMP_WORDS}\fP of the word containing the current
cursor position.
This variable is available only in shell functions invoked by the
programmable completion facilities (see Programmable Completion\fP
below).
-
COMP_LINE
-
The current command line.
This variable is available only in shell functions and external
commands invoked by the
programmable completion facilities (see Programmable Completion\fP
below).
-
COMP_POINT
-
The index of the current cursor position relative to the beginning of
the current command.
If the current cursor position is at the end of the current command,
the value of this variable is equal to ${#COMP_LINE}\fP.
This variable is available only in shell functions and external
commands invoked by the
programmable completion facilities (see Programmable Completion\fP
below).
The following variables are used by the shell. In some cases,
bash
assigns a default value to a variable; these cases are noted
below.
-
IFS
-
The
Internal Field Separator
that is used
for word splitting after expansion and to
split lines into words with the
read
builtin command. The default value is
``<space><tab><newline>''.
-
PATH
-
The search path for commands. It
is a colon-separated list of directories in which
the shell looks for commands (see
.SM
COMMAND EXECUTION
below). The default path is system-dependent,
and is set by the administrator who installs
.BR bash .
A common value is ``/usr/gnu/bin:/usr/local/bin:/usr/ucb:/bin:/usr/bin:.''.
-
HOME
-
The home directory of the current user; the default argument for the
cd\fP builtin command.
The value of this variable is also used when performing tilde expansion.
-
CDPATH
-
The search path for the
cd
command.
This is a colon-separated list of directories in which the shell looks
for destination directories specified by the
cd
command.
A sample value is ``.:~:/usr''.
-
BASH_ENV
-
If this parameter is set when bash\fP is executing a shell script,
its value is interpreted as a filename containing commands to
initialize the shell, as in
.IR ~/.bashrc .
The value of
.SM
BASH_ENV
is subjected to parameter expansion, command substitution, and arithmetic
expansion before being interpreted as a file name.
.SM
PATH
is not used to search for the resultant file name.
-
MAIL
-
If this parameter is set to a file name and the
.SM
MAILPATH
variable is not set,
bash
informs the user of the arrival of mail in the specified file.
-
MAILCHECK
-
Specifies how
often (in seconds)
bash
checks for mail. The default is 60 seconds. When it is time to check
for mail, the shell does so before displaying the primary prompt.
If this variable is unset, the shell disables mail checking.
-
MAILPATH
-
A colon-separated list of file names to be checked for mail.
The message to be printed when mail arrives in a particular file
may be specified by separating the file name from the message with a `?'.
When used in the text of the message, $_\fP expands to the name of
the current mailfile.
Example:
-
PS1
-
The value of this parameter is expanded (see
.SM
PROMPTING
below) and used as the primary prompt string. The default value is
``\s-\v\$ \fP''.
-
PS2
-
The value of this parameter is expanded as with
PS1
and used as the secondary prompt string. The default is
``> \fP''.
-
PS3
-
The value of this parameter is used as the prompt for the
select
command (see
.SM
SHELL GRAMMAR
above).
-
PS4
-
The value of this parameter is expanded as with
PS1
and the value is printed before each command
bash
displays during an execution trace. The first character of
.SM
PS4
is replicated multiple times, as necessary, to indicate multiple
levels of indirection. The default is ``+ \fP''.
-
TIMEFORMAT
-
The value of this parameter is used as a format string specifying
how the timing information for pipelines prefixed with the
time
reserved word should be displayed.
The %\fP character introduces an escape sequence that is
expanded to a time value or other information.
The escape sequences and their meanings are as follows; the
braces denote optional portions.
.sp .5
-
%%
-
A literal %\fP.
-
%[p\fP][l]R
-
The elapsed time in seconds.
-
%[p\fP][l]U
-
The number of CPU seconds spent in user mode.
-
%[p\fP][l]S
-
The number of CPU seconds spent in system mode.
-
%P
-
The CPU percentage, computed as (%U + %S) / %R.
-
HISTSIZE
-
The number of commands to remember in the command history (see
.SM
HISTORY
below). The default value is 500.
-
HISTFILE
-
The name of the file in which command history is saved (see
.SM
HISTORY
below). The default value is ~/.bash_history\fP. If unset, the
command history is not saved when an interactive shell exits.
-
HISTFILESIZE
-
The maximum number of lines contained in the history file. When this
variable is assigned a value, the history file is truncated, if
necessary, to contain no more than that number of lines. The default
value is 500. The history file is also truncated to this size after
writing it when an interactive shell exits.
-
OPTERR
-
If set to the value 1,
bash
displays error messages generated by the
getopts
builtin command (see
.SM
SHELL BUILTIN COMMANDS
below).
.SM
OPTERR
is initialized to 1 each time the shell is invoked or a shell
script is executed.
-
LANG
-
Used to determine the locale category for any category not specifically
selected with a variable starting with LC_\fP.
-
LC_ALL
-
This variable overrides the value of LANG\fP and any other
LC_\fP variable specifying a locale category.
-
LC_COLLATE
-
This variable determines the collation order used when sorting the
results of pathname expansion, and determines the behavior of range
expressions, equivalence classes, and collating sequences within
pathname expansion and pattern matching.
-
LC_CTYPE
-
This variable determines the interpretation of characters and the
behavior of character classes within pathname expansion and pattern
matching.
-
LC_MESSAGES
-
This variable determines the locale used to translate double-quoted
strings preceded by a $\fP.
-
LC_NUMERIC
-
This variable determines the locale category used for number formatting.
-
PROMPT_COMMAND
-
If set, the value is executed as a command prior to issuing each primary
prompt.
-
IGNOREEOF
-
Controls the
action of an interactive shell on receipt of an
.SM
EOF
character as the sole input. If set, the value is the number of
consecutive
.SM
EOF
characters which must be
typed as the first characters on an input line before
bash
exits. If the variable exists but does not have a numeric value, or
has no value, the default value is 10. If it does not exist,
.SM
EOF
signifies the end of input to the shell.
-
TMOUT
-
If set to a value greater than zero, the value is interpreted as the
number of seconds to wait for input after issuing the primary prompt.
Bash
terminates after waiting for that number of seconds if input does
not arrive.
-
FCEDIT
-
The default editor for the
fc
builtin command.
-
FIGNORE
-
A colon-separated list of suffixes to ignore when performing
filename completion (see
.SM
READLINE
below).
A filename whose suffix matches one of the entries in
.SM
FIGNORE
is excluded from the list of matched filenames.
A sample value is ``.o:~''.
-
GLOBIGNORE
-
A colon-separated list of patterns defining the set of filenames to
be ignored by pathname expansion.
If a filename matched by a pathname expansion pattern also matches one
of the patterns in
.SM
.BR GLOBIGNORE ,
it is removed from the list of matches.
-
INPUTRC
-
The filename for the
readline
startup file, overriding the default of
.FN ~/.inputrc
(see
.SM
READLINE
below).
-
HISTCONTROL
-
If set to a value of
.IR ignorespace ,
lines which begin with a
space
character are not entered on the history list.
If set to a value of
.IR ignoredups ,
lines matching the last history line are not entered.
A value of
ignoreboth
combines the two options.
If unset, or if set to any other value than those above,
all lines read
by the parser are saved on the history list, subject to the value
of
.BR HISTIGNORE .
This variable's function is superseded by
.BR HISTIGNORE .
The second and subsequent lines of a multi-line compound command are
not tested, and are added to the history regardless of the value of
.BR HISTCONTROL .
-
HISTIGNORE
-
A colon-separated list of patterns used to decide which command lines
should be saved on the history list. Each pattern is anchored at the
beginning of the line and must match the complete line (no implicit
`*\fP' is appended). Each pattern is tested against the line
after the checks specified by
HISTCONTROL
are applied.
In addition to the normal shell pattern matching characters, `&\fP'
matches the previous history line. `&\fP' may be escaped using a
backslash; the backslash is removed before attempting a match.
The second and subsequent lines of a multi-line compound command are
not tested, and are added to the history regardless of the value of
.BR HISTIGNORE .
-
histchars
-
The two or three characters which control history expansion
and tokenization (see
.SM
HISTORY EXPANSION
below). The first character is the history expansion\fP character,
the character which signals the start of a history
expansion, normally `!\fP'.
The second character is the quick substitution\fP
character, which is used as shorthand for re-running the previous
command entered, substituting one string for another in the command.
The default is `^\fP'.
The optional third character is the character
which indicates that the remainder of the line is a comment when found
as the first character of a word, normally `#\fP'. The history
comment character causes history substitution to be skipped for the
remaining words on the line. It does not necessarily cause the shell
parser to treat the rest of the line as a comment.
-
HOSTFILE
-
Contains the name of a file in the same format as
.FN /etc/hosts
that should be read when the shell needs to complete a
hostname.
The list of possible hostname completions may be changed while the
shell is running;
the next time hostname completion is attempted after the
value is changed,
bash
adds the contents of the new file to the existing list.
If
.SM
HOSTFILE
is set, but has no value, bash\fP attempts to read
.FN /etc/hosts
to obtain the list of possible hostname completions.
When
.SM
HOSTFILE
is unset, the hostname list is cleared.
-
auto_resume
-
This variable controls how the shell interacts with the user and
job control. If this variable is set, single word simple
commands without redirections are treated as candidates for resumption
of an existing stopped job. There is no ambiguity allowed; if there is
more than one job beginning with the string typed, the job most recently
accessed is selected. The
name
of a stopped job, in this context, is the command line used to
start it.
If set to the value
.IR exact ,
the string supplied must match the name of a stopped job exactly;
if set to
.IR substring ,
the string supplied needs to match a substring of the name of a
stopped job. The
substring
value provides functionality analogous to the
%?
job identifier (see
.SM
JOB CONTROL
below). If set to any other value, the supplied string must
be a prefix of a stopped job's name; this provides functionality
analogous to the
%
job identifier.
-
COMPREPLY
-
An array variable from which bash\fP reads the possible completions
generated by a shell function invoked by the programmable completion
facility (see Programmable Completion\fP below).
Up
Next
Previous