APPENDIX A
Shell Variables
This list is excerpted from the bash man page and edited to make a stand-alone document. The following variables are set by bash .
BASH
Expands to the full file name used to invoke this instance of bash .
BASHPID
Expands to the process ID of the current bash process. This differs from $$ under certain circumstances, such as subshells that do not require bash to be reinitialized.
BASH_ALIASES
An associative array variable whose members correspond to the internal list of aliases as maintained by the alias builtin. Elements added to this array appear in the alias list; unsetting array elements causes aliases to be removed from the alias list.
BASH_ARGC
An array variable whose values are the number of parameters in each frame of the current bash execution call stack. The number of parameters to the current subroutine (shell function or script executed with . or source) is at the top of the stack. When a subroutine is executed, the number of parameters passed is pushed onto BASH_ARGC . The shell sets BASH_ARGC only when in extended debugging mode (see the description of the extdebug option to the shopt builtin in the bash man page).
BASH_ARGV
An array variable containing all the parameters in the current bash execution call stack. The final parameter of the last subroutine call is at the top of the stack; the first parameter of the initial call is at the bottom. When a subroutine is executed, the parameters supplied are pushed onto BASH_ARGV . The shell sets BASH_ARGV only when in extended debugging mode (see the description of the extdebug option to the shopt builtin in the bash man page).
BASH_CMDS
An associative array variable whose members correspond to the internal hash table of commands as maintained by the hash builtin. Elements added to this array appear in the hash table; unsetting array elements causes commands to be removed from the hash table.
BASH_COMMAND
The command currently being executed or about to be executed, unless the shell is executing a command as the result of a trap, in which case it is the command executing at the time of the trap.
BASH_EXECUTION_STRING
The command argument to the -c invocation option.
BASH_LINENO
An array variable whose members are the line numbers in source files corresponding to each member of FUNCNAME . ${BASH_LINENO[$i]} is the line number in the source file where ${FUNCNAME[$i]} was called (or ${BASH_LINENO[$i-1]} if referenced within another shell function). The corresponding source file name is ${BASH_SOURCE[$i]} . Use LINENO to obtain the current line number.
BASH_REMATCH
An array variable whose members are assigned by the =~ binary operator to the [[ conditional command. The element with index is the portion of the string matching the entire regular expression. The element with index n is the portion of the string matching the nth parenthesized subexpression. This variable is read-only.
BASH_SOURCE
An array variable whose members are the source file names corresponding to the elements in the FUNCNAME array variable.
BASH_SUBSHELL
Incremented by one each time a subshell or subshell environment is spawned. The initial value is 0.
BASH_VERSINFO
A read-only array variable whose members hold version information for this instance of bash . The values assigned to the array members are as follows:
- BASH_VERSINFO[0] : The major version number (the release)
- BASH_VERSINFO[1] : The minor version number (the version)
- BASH_VERSINFO[2] : The patch level
- BASH_VERSINFO[3] : The build version
- BASH_VERSINFO[4] : The release status (e.g., beta1 )
- BASH_VERSINFO[5] : The value of MACHTYPE
BASH_VERSION
Expands to a string describing the version of this instance of bash .
COMP_CWORD
An index into ${COMP_WORDS} 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 in the bash man page).
COMP_KEY
The key (or final key of a key sequence) used to invoke the current completion function.
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 in the bash man page).
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} . This variable is available only in shell functions and external commands invoked by the programmable completion facilities (see Programmable Completion in the bash man page).
COMP_TYPE
Set to an integer value corresponding to the type of completion attempted that caused a completion function to be called: TAB for normal completion, ? for listing completions after successive tabs, ! for listing alternatives on partial word completion, @ to list completions if the word is not unmodified, or % for menu completion. This variable is available only in shell functions and external commands invoked by the programmable completion facilities (see Programmable Completion in the bash man page).
COMP_WORDBREAKS
The set of characters that the readline library treats as word separators when performing word completion. If COMP_ WORDBREAKS is unset, it loses its special properties, even if it is subsequently reset.
COMP_WORDS
An array variable (see Arrays in the bash man page) consisting of the individual words in the current command line. The line is split into words as readline would split it, using COMP_WORDBREAKS as described previously. This variable is available only in shell functions invoked by the programmable completion facilities (see Programmable Completion in the bash man page).
DIRSTACK
An array variable (see Arrays in the bash man page) 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 DIRSTACK is unset, it loses its special properties, even if it is subsequently reset.
EUID
Expands to the effective user ID of the current user, initialized at shell startup. This variable is read-only.
FUNCNAME
An array variable containing the names of all shell functions currently in the execution call stack. The element with index 0 is the name of any currently executing shell function. The bottom-most element is main . This variable exists only when a shell function is executing. Assignments to FUNCNAME have no effect and return an error status. If FUNCNAME is unset, it loses its special properties, even if it is subsequently reset.
GROUPS
An array variable containing the list of groups of which the current user is a member. Assignments to GROUPS have no effect and return an error status. If GROUPS 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 HISTCMD is unset, it loses its special properties, even if it is subsequently reset.
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.
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 LINENO is unset, it loses its special properties, even if it is subsequently reset.
Next page