$* in bash scripting

From the man page:

* Expands to the positional parameters, starting from one. When the expansion occurs within double quotes, it expands to a single word with the value of each parameter separated by the first character of the IFS special variable. That is, "$*" 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.

So it is equivalent to all the positional parameters, with slightly different semantics depending on whether or not it is in quotes.


See this page:

http://tldp.org/LDP/abs/html/internalvariables.html#IFSEMPTY

The behavior of $* and $@ when $IFS is empty depends + on which Bash or sh version being run. It is therefore inadvisable to depend on this "feature" in a script.


It's all the arguments passed to the script, except split by word. You almost always want to use "$@" instead. And it's all in the bash(1) man page.

Tags:

Scripting

Bash