Documentation on Bash special parameters:
$* $@ $# $? $- $$ $! $0 $_
can be found in the Bash Reference Manual, specifically in section 3.4.2, "Special Parameters". If you have the bash documentation installed on your system, you can type
% info bash
and then search for "Special Parameters".
As rici points out in a comment, within the info
command you can also find the special parameters via the index: type i
and then type the single character (excluding the $
), then Enter. This doesn't work for ?
, and searching for !
finds a different section first (typing ,
to find the next entry works). (This still works reasonably well after I apply my patch.)
It's unfortunate, IMHO, that this section refers to these parameters without the leading $
character. (I've just submitted a patch that changes this.)
A brief summary (but read the manual for details):
$*
: Expands to the positional parameters starting with $1
.
$@
: Also expands to the positional parameters, but behaves differently when enclosed in double quotes.
$#
: Expands to the number of positional parameters in decimal.
$?
: Expands to the exit status of the most recent command. (Similar to $status
in csh and tcsh.)
$-
: Expands to the current option flags.
$!
: Expands to the process ID of the most recent background command.
$0
: Expands to the name of the shell or script. (Note that $0
, unlike $1
et al, is not a positional parameter.)
$_
: Initially set to the absolute pathname use to invoke the shell or shell script, later set to the last argument of the previous command. (There's more; see the manual.)
UPDATE :
As of bash version 4.3, released 2014-02-26, the bash documentation is annotated to show the full names of these variables. In release 4.2:
`#'
Expands to the number of positional parameters in decimal.
In release 4.3:
`#'
($#) Expands to the number of positional parameters in decimal.