Meaning of dollar sign variables in bash script (with examples)
$1
,$2
,$3
, … are the positional parameters. e.g.
$@
: an array-like construct of all positional parameters, {$1
,$2
,$3
, …}. e.g.
$*
is the IFS (Internal Field Separator) expansion of all positional parameters,$1
,$2
,$3
, …. It looks similar to but is still different from$@
depending on the special shell variable$IFS
and whether$*
is double quoted or not. See here for more details. e.g.
$#
is the number of positional parameters. e.g.
$-
current options set for the shell. See this post for some common shell options available, and this post for more details on$-
. e.g.
- $$ pid of the current shell (not subshell)
- $_ most recent parameter (or the absolute path of the command to start the current shell immediately after startup)
-
$IFS
the (input) field separator, see how it’s used together with$*
as described above -
$?
most recent foreground pipeline exit status. -
$!
PID of the most recent background command -
$0
name of the shell or shell script
Reference: http://stackoverflow.com/questions/5163144/what-are-the-special-dollar-sign-shell-variables