This question already has an answer here:
- What's the difference between [email protected] and $* in UNIX? 4 answers
I always use
[email protected] when I want all arguments of bash function but recently I just found that
$* also works in the same way, and it also can use as array index.
My question is What is difference between
[email protected] in Bash? and which one should I prefer?
The Bash manual is quite clear on this topic:
All of the positional parameters, seen as a single word.
$*must be quoted.
$*, but each parameter is a quoted string, that is, the parameters are passed on intact, without interpretation or expansion. This means, among other things, that each parameter in the argument list is seen as a separate word.
Note: Of course,
[email protected]should be quoted.