====== Special parameters and shell variables ======
===== Special Parameters =====
^parameter^character^expansion description^
|''*''|asterisk|The positional parameters starting from the first. When used inside doublequotes (see [[syntax:quoting | quoting]]), like ''"$*"'', it expands to all positional parameters //as one word//, delimited by the first character of the ''IFS'' variable (a space in this example): ''"$1 $2 $3 $4"''. \\ If ''IFS'' is unset, the delimiter used will be always a space, if ''IFS'' is NULL, the delimiter will be nothing, which effectively concatenates all the positional parameters without any delimiter. \\ When used unquoted, it will just expand to the strings, one by one, not preserving the word boundaries (i.e. word splitting will split the text again, if it contains ''IFS'' characters. \\ See also the [[scripting:posparams | scripting article about handling positional parameters]].|
|''@''|at-sign|The positional parameters starting from the first. When used inside doublequotes (see [[syntax:quoting | quoting]]), like ''"$@"'', it expands all positional parameters //as separate words//: ''"$1" "$2" "$3" "$4"'' \\ Without doublequotes, the behaviour is like the one of ''*'' without doublequotes. \\ See also the [[scripting:posparams | scripting article about handling positional parameters]].|
|''#''|hash mark|Number of positional parameters (decimal) \\ See also the [[scripting:posparams | scripting article about handling positional parameters]].|
|''?''|question mark|Status of the most recently executed foreground-pipeline (exit/return code)|
|''-''|dash|Current option flags set by the shell itself, on invocation, or using the [[commands:builtin:set | set builtin command]]. It's just a set of characters, like ''himB'' for ''h'', ''i'', ''m'' and ''B''.|
|''$''|dollar-sign|The process ID (PID) of the shell. In an [[syntax:ccmd:grouping_subshell | explicit subshell]] it expands to the PID of the current "main shell", not the subshell. This is different from ''$BASHPID''!|
|''!''|exclamation mark|The process ID (PID) of the most recently executed background pipeline (like started with ''command &'')|
|''0''|zero|The name of the shell or the shell script (filename). Set by the shell itself. \\ If Bash is started with a filename to execute (script), it's set to this filename. If started with the ''-c <CMDLINE>'' option (commandline given as argument), then ''$0'' will be the first argument after the given ''<CMDLINE>''. Otherwise, it is set to the string given on invocation for ''argv[0]''. \\ Unlike popular belief, ''$0'' is //not a positional parameter//.|
|''_''|underscore|A kind of catch-all parameter. Directly after shell invocation, it's set to the filename used to invoke Bash, or the absolute or relative path to the script, just like ''$0'' would show it. Subsequently, expands to the last argument to the previous command. Placed into the environment when executing commands, and set to the full pathname of these commands. When checking mail, this parameter holds the name of the mail file currently being checked.|
===== Shell Variables =====
==== BASH ====
^Variable: |''BASH'' ^Since: |unknown |
^Type: |normal variable ^Read-only: |no |
^Set by Bash: |yes ^Default: |n/a |
Expands to the full file name used to invoke the current instance of Bash.
==== BASHOPTS ====
^Variable: |''BASHOPTS'' ^Since: |4.1-alpha |
^Type: |normal variable ^Read-only: |yes |
^Set by Bash: |yes ^Default: |n/a |
A colon-separated list of enabled shell options.
Each word in the list is a valid argument for the ''-s'' option to the
[[commands:builtin:shopt|shopt builtin command]]. The options appearing
in ''BASHOPTS'' are those reported as on by ''shopt''. If this variable is
in the environment when Bash starts up, each shell option in the list will
Always expands to the process ID of the current Bash process. This
differs from the special parameter ''$'' under certain circumstances,
such as subshells that do not require Bash to be re-initialized.
==== BASH_ALIASES ====
^Variable: |''BASH_ALIASES'' ^Since: |unknown |
^Type: |associative array ^Read-only: |no |
^Set by Bash: |yes ^Default: |n/a |
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 cause aliases to be removed from the alias list.
The associative key is the name of the alias as used with the
[[commands:builtin:alias | alias builtin command]].
==== BASH_ARGC ====
^Variable: |''BASH_ARGC'' ^Since: |3.0 |
^Type: |integer indexed array ^Read-only: |no |
^Set by Bash: |only in extended debugging mode ^Default: |n/a |
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 [[commands:builtin:source|''.'' or ''source'' builtin command]])
is at the top of the stack.
When a subroutine is executed, the number of parameters passed is pushed onto ''BASH_ARGC''.
==== BASH_ARGV ====
^Variable: |''BASH_ARGV'' ^Since: |3.0 |
^Type: |integer indexed array ^Read-only: |no |
^Set by Bash: |only in extended debugging mode ^Default: |n/a |
An array variable containing all of 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''.
==== BASH_ARGV0 ====
^Variable: |''BASH_ARGV0'' ^Since: |5.0-alpha |
^Type: |string ^Read-only: |no |
^Set by Bash: |yes ^Default: |same as ''$0'' |
Expands to the name of the shell or shell script - as the special parameter ''$0'' does. Assignments to ''BASH_ARGV0'' causes the value to be assigned to ''$0''.
If this parameter is unset, it loses its special properties, even if subsequently reset.
==== BASH_CMDS ====
^Variable: |''BASH_CMDS'' ^Since: |unknown |
^Type: |associative array ^Read-only: |no |
^Set by Bash: |yes ^Default: |n/a |
An associative array variable whose members correspond to the
internal hash table of commands as maintained by the [[commands:builtin:hash|hash builtin command]].
Elements added to this array appear in the hash table;
unsetting array elements cause commands to be removed from the hash table.
The associative key is the name of the command as used with the[[commands:builtin:hash|hash builtin command]].
==== BASH_COMMAND ====
^Variable: |''BASH_COMMAND'' ^Since: |3.0 |
^Type: |normal variable ^Read-only: |no |
^Set by Bash: |yes ^Default: |n/a |
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_COMPAT ====
^Variable: |''BASH_COMPAT'' ^Since: |4.3-alpha |
^Type: |normal variable ^Read-only: |no |
^Set by Bash: |no ^Default: |n/a |
The value is used to set the shell's compatibility level. The value may be a decimal number (e.g., ''4.2'') or an integer (e.g., ''42'') corresponding to the desired compatibility level. If ''BASH_COMPAT'' is unset or set to the empty string, the compatibility level is set to the default for the current version. If ''BASH_COMPAT'' is set to a value that is not one of the valid compatibility levels, the shell prints an error message and sets the compatibility level to the default for the current version. The valid compatibility levels correspond to the compatibility options accepted by the shopt builtin. The current version is also a valid value.
The element with index 0 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.
Before Bash version 5.1-alpha this variable was readonly.
==== BASH_SOURCE ====
^Variable: |''BASH_SOURCE'' ^Since: |3.0 |
^Type: |integer indexed array ^Read-only: |no |
^Set by Bash: |yes ^Default: |n/a |
An array variable whose members are the source filenames corresponding to the
elements in the ''FUNCNAME'' array variable.
==== BASH_SUBSHELL ====
^Variable: |''BASH_SUBSHELL'' ^Since: |3.0 |
^Type: |normal variable ^Read-only: |no |
^Set by Bash: |yes ^Default: |n/a |
Incremented by one each time a subshell or subshell environment is spawned.
The initial value is 0.
==== BASH_VERSINFO ====
^Variable: |''BASH_VERSINFO'' ^Since: |2.0 |
^Type: |integer indexed array ^Read-only: |yes |
^Set by Bash: |yes ^Default: |n/a |
A readonly 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 ====
^Variable: |''BASH_VERSION'' ^Since: |unknown |
^Type: |normal variable ^Read-only: |no |
^Set by Bash: |yes ^Default: |n/a |
Expands to a string describing the version of this instance of Bash.
Since Bash 2.0 it includes the shell's "release status" (alpha[N], beta[N], release).
==== CHILD_MAX ====
^Variable: |''CHILD_MAX'' ^Since: |4.3-alpha |
^Type: |normal variable ^Read-only: |no |
^Set by Bash: |no ^Default: |n/a |
Set the number of exited child status values for the shell to remember. Bash will not allow this value to be decreased below a POSIX-mandated minimum, and there is a maximum value (currently 8192) that this may not exceed. The minimum value is system-dependent.
==== COMP_CWORD ====
^Variable: |''COMP_CWORD'' ^Since: |unknown |
^Type: |normal variable ^Read-only: |no |
^Set by Bash: |only for programmable completion facilities ^Default: |n/a |
An index into ''COMP_WORDS'' of the word containing the current cursor position.
==== COMP_KEY ====
^Variable: |''COMP_KEY'' ^Since: |unknown |
^Type: |normal variable ^Read-only: |no |
^Set by Bash: |only for programmable completion facilities ^Default: |n/a |
The key (or final key of a key sequence) used to invoke the current completion
function.
==== COMP_LINE ====
^Variable: |''COMP_LINE'' ^Since: |unknown |
^Type: |normal variable ^Read-only: |no |
^Set by Bash: |only for programmable completion facilities ^Default: |n/a |
The current command line.
==== COMP_POINT ====
^Variable: |''COMP_POINT'' ^Since: |unknown |
^Type: |normal variable ^Read-only: |no |
^Set by Bash: |only for programmable completion facilities ^Default: |n/a |
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}''.
==== COMP_TYPE ====
^Variable: |''COMP_TYPET'' ^Since: |unknown |
^Type: |normal variable ^Read-only: |no |
^Set by Bash: |only for programmable completion facilities ^Default: |n/a |
Set to an integer value corresponding to the type of completion
attempted that caused a completion function to be called:
|''TAB'' |normal completion |
|''?'' |listing completions after successive tabs |
|''!'' |listing alternatives on partial word completion |
|''@'' |to list completions if the word is not unmodified |
The value of this parameter is expanded as with PS1 and used as
the secondary prompt string.
==== PS3 ====
^Variable: |''PS3'' ^Since: |unknown |
^Type: |normal variable ^Read-only: |no |
^Set by Bash: |no ^Default: |n/a |
The value of this parameter is used as the prompt for the select
command.
==== PS4 ====
^Variable: |''PS4'' ^Since: |unknown |
^Type: |normal variable ^Read-only: |no |
^Set by Bash: |if unset ^Default: |"''+ ''" |
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 ''PS4'' is replicated multiple
times, as necessary, to indicate multiple levels of indirection.
==== SHELL ====
^Variable: |''SHELL'' ^Since: |unknown |
^Type: |normal variable ^Read-only: |no |
^Set by Bash: |no ^Default: |n/a |
The full pathname to the shell is kept in this environment variable.
If it is not set when the shell starts, Bash assigns the full pathname
of the current user's login shell.
==== SRANDOM ====
^Variable: |''SRANDOM'' ^Since: |5.1-alpha |
^Type: |normal variable ^Read-only: |no |
^Set by Bash: |yes ^Default: |n/a |
A variable that delivers a 32bit random number. The random number generation uses platform specific generators in the background and a builtin fallback generator.
==== TIMEFORMAT ====
^Variable: |''TIMEFORMAT'' ^Since: |unknown |
^Type: |normal variable ^Read-only: |no |
^Set by Bash: |no ^Default: |n/a |
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 % 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:
|''%%'' |a literal ''%'' (percent sign) |
|''%[p][l]R'' |elapsed time in seconds |
|''%[p][l]U'' |number of CPU seconds spent in user mode |
|''%[p][l]S'' |number of CPU seconds spent in system mode |
|''p'' |A digit specifying the precision. A value of 0 causes no decimal point or fraction to be output. At most three digits after the decimal point are shown. If not specified, the value 3 is used. |
|''l'' |A longer format, including minutes, of the form MMmSS.FFs. The value of p determines whether or not the fraction is included. |
If this variable is not set, Bash acts as if it had the value