Special Parameters Flashcards
- 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 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 article about handling positional parameters. https://web.archive.org/web/20230318164746/https://wiki.bash-hackers.org/scripting/posparams
@ 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. 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.</CMDLINE></CMDLINE>
_ 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.