Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is difference between `$*` an `$@` in Bash [duplicate]

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?

like image 310
fronthem Avatar asked Aug 26 '15 08:08

fronthem


1 Answers

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.

like image 91
Manuel Barbe Avatar answered Sep 27 '22 23:09

Manuel Barbe