LinuxQuestions.org

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

vinaytp 10-26-2009 09:01 AM

confused with $* and $@
 
Hi all...

I am not able to distinguish between $* and $@, both will store the list of positional parameters...

echo $*
echo $@

are giving me same results even when command line arguments are quoted....

Help me please

Thanks in advnace....

avijitp 10-26-2009 09:06 AM

Googled and found this:

Code:


$* command-line arguments as one string

$@ command-line arguments as list of strings (useful for writing wrapper shell scripts that just add one argument)


catkin 10-26-2009 12:01 PM

Quote:

Originally Posted by vinaytp (Post 3732860)
giving me same results even when command line arguments are quoted

This illustrates the difference, initially with what you may have tried with apparently the same results for each (they're not the same but you can't see the difference) and then using them in a way that shows the difference
Code:

c:~$ set 'a b' c
c:~$ echo "$*"
a b c
c:~$ echo "$@"
a b c
c:~$ for var in "$@"; do echo $var; done
a b
c
c:~$ for var in "$*"; do echo $var; done
a b c
c:~$


chrism01 10-26-2009 06:18 PM

http://tldp.org/LDP/Bash-Beginners-G...ml#table_03_01


All times are GMT -5. The time now is 04:07 PM.