For years and on dozens of occasions, I have hesitated between the use of $* and [email protected] in shell scripts. Having read the applicable section of Bash's manpage over and over again, having tried both $* and [email protected], I more or less completely fail to understand the practical difference of application between the two variables. Can you enlighten me, please?

I have been using $* recently, but don't ask me why. I don't know why, because I don't know why [email protected] even exists, except as an almost exact synonym for $*.

Is there any practical difference?

(I personally tend to use Bash, but remain agnostic regarding the choice of shell. My question is not specific to Bash as far as I know.)

网友答案:

Unquoted, there is no difference -- they're expanded to all the arguments and they're split accordingly. The difference comes when quoting. "[email protected]" expands to properly quoted arguments and "$*" makes all arguments into a single argument. Take this for example: