Bash Special Parameters: Difference between revisions
(→$*) |
(→$@) |
||
Line 29: | Line 29: | ||
man bash | grep -C2 '$@' | man bash | grep -C2 '$@' | ||
<font color=darkgray>TODO: https://github.com/koalaman/shellcheck/wiki/SC2145</font> | |||
=$?= | =$?= |
Latest revision as of 19:48, 25 January 2021
External
Internal
$0
The name of the shell or shell script. This will have the full pathname if it was found via a PATH search.
$*
$* expands to the positional parameters, starting from one. When the expansion occurs within double quotes, $* coalesces all individual parameters into a single parameter, by expanding them to a single word with the value of each parameter separated by the first character of the IFS special variable: "$*" is equivalent to "$1c$2c...", where c is the first character of the value of the IFS variable. If IFS is unset, the parameters are separated by spaces. If IFS is null, the parameters are joined without intervening separators.
Also see:
TODO: https://github.com/koalaman/shellcheck/wiki/SC2145
$@
$@ expands to the positional parameters, starting from one.
When the expansion occurs within double quotes, each parameter expands to a separate word. That is, "$@" is equivalent to individually quoted "$1" "$2" ... If no double quotes are set around $@, then each space-bordered component is passed individually to the target function.
If the double-quoted expansion occurs within a word, the expansion of the first parameter is joined with the beginning part of the original word, and the expansion of the last parameter is joined with the last part of the original word. When there are no positional parameters, "$@" and $@ expand to nothing and they are removed.
man bash | grep -C2 '$@'
TODO: https://github.com/koalaman/shellcheck/wiki/SC2145
$?
Exit value of last executed command or function, in the interactive shell or within a script.
$$
The PID of the current bash process. Also see BASHPID, which differs from $$ under certain circumstances, such as subshells that do not require bash to be re-initialized.
$#
The number of command line or a function's arguments.
$-
Options currently in effect (supplied on command line or to set). The shell sets some options automatically.
$
Process number of the shell.
$!
Process number (PID) of most recently executed background command.
$_
Temporary variable; initialized to pathname of script or program being executed. Later, stores the last argument of previous command. Also stores name of matching MAIL file during mail checks.