LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   difference between $@ and $* (https://www.linuxquestions.org/questions/linux-newbie-8/difference-between-%24%40-and-%24%2A-769593/)

shibu_sp 11-17-2009 12:25 AM

difference between $@ and $*
 
Dear all

what is difference between $@ and $* in UNIX Shell script

Thanks and regards
Shibu

David the H. 11-17-2009 01:00 AM

"$*" outputs all parameters ($1, $2, etc) as a single unit. For that reason it's supposed to always be quoted, or else bash's word separation function will also affect the output.

"$@" outputs all parameters as individual items, that is, loops and things like that will treat each item as a separate unit, whether they have spaces in them or not. Note that you still have to quote the variable to prevent word separation though.

The same pattern works in array elements as well.

The section on positional parameters on this page details the behavior:
http://www.tldp.org/LDP/abs/html/internalvariables.html


All times are GMT -5. The time now is 08:52 AM.