I always use $@ 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 $* an $@ 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.
Note:
$*must be quoted.
$@Same as
$*, 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,
$@should be quoted.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With