| parameter | character | expansion description |
|---|---|---|
* | asterisk | The positional parameters starting from the first. When used inside doublequotes (see quoting), like "$*", it expands to all positional parameters as one word, delimited by the first character if 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 article about handling positional parameters. |
@ | at-sign | The positional parameters starting from the first. When used inside doublequotes (see 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 article about handling positional parameters. |
# | hash mark | Number of positional parameters (decimal) See also the 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 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 explicit subshell it expands to the PID of the current "main shell", not the subshell. |
! | 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. 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. |
Not all, only the most interesting ones. If you think somethin's missing here - feel free to extend the table at any time.
IFS | The Internal Field Separator, used to split input into separate fields after reading with the read command. Also used to split fields in various other situations, like mass-populating an array. |
IGNOREEOF | An integer that indicates how much EOF characters the shell must receive (in a row) to finally exit. If it exists and is empty or non-integer, the default of 10 is assumed. If it's unset, every EOF exits the shell. |
PIPESTATUS | An array indicating the exit code of every part of a pipeline construct. The normal exit code $? would only reflect the status of the pipeline as a whole. From a construct cat foo | grep bar, PIPESTATUS[0] would be the cat command, PIPESTATUS[1] would be the grep. |
SECONDS | Each time referenced, expands to the number of seconds since shell startup. Once unset, it looses its special meaning. |
SHELLOPTS | Expands to a : (colon) separated list of shell options set (with the set builtin command) using their long option names |
RANDOM | Each time referenced, it expands to a value between 0 and 32767. The random generator may be re-initialized by assigning a value to it. Once unset, it looses its special meaning, even is re-set. To get a random number from 0 to a specific maximum, use the modulo arithmetic operation: RANDOM % 100 |
BASHPID | Always expands to the process ID (PID) of the current used shell (this is different from $$!) |
PROMPT_DIRTRIM | If set to a positive integer, the expansion of the current directory in the PS1 prompt will be trimmed with "..." if more than PROMPT_DIRTRIM pathname components would be shown |
Discussion