whats the difference between $* and $@


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting whats the difference between $* and $@
# 1  
Old 01-14-2008
whats the difference between $* and $@

Hi,

whats the difference between $* and $@ in command line arguments to a shell scripts
# 2  
Old 01-14-2008
$* = all the arguments are double quoted. If a script receives 2 arguments, $* is equivalent to $1 $2

$@ All the arguments are individually double quoted,If a script receives 2 arguments, $@ is equivalent to $1 $2
# 3  
Old 01-14-2008
Quote:
Originally Posted by invinzin21
$* = all the arguments are double quoted. If a script receives 2 arguments, $* is equivalent to $1 $2

$@ All the arguments are individually double quoted,If a script receives 2 arguments, $@ is equivalent to $1 $2
in both cases
Quote:
If a script receives 2 arguments, $*/$@ is equivalent to $1 $2
cat scr


for i in $@
do
echo "@ $i"
done
for j in $*
do
echo "* $j"
done




./scr a b c "d e"
@ a
@ b
@ c
@ d
@ e
* a
* b
* c
* d
* e

can we see some diff through this kind of script ???
# 4  
Old 01-14-2008
Quote:
Originally Posted by pbsrinivas
Hi,

whats the difference between $* and $@ in command line arguments to a shell scripts
Look into man sh under the section 'Special Parameters'
Code:
       *      Expands  to the positional parameters, starting from one.  When
              the expansion occurs within double quotes, it expands to a sin-
              gle  word  with  the  value  of each parameter separated by the
              first character of the IFS special variable.  That is, "$*"  is
              equivalent  to  "$1c$2c...",  where c is the first character of
              the value of the IFS variable.  If IFS is unset, the parameters
              are  separated  by  spaces.  If IFS is null, the parameters are
              joined without intervening separators.
       @      Expands to the positional parameters, starting from one.   When
              the  expansion  occurs  within  double  quotes,  each parameter
              expands to a separate word.  That is,  "$@"  is  equivalent  to
              "$1"  "$2"  ...   When there are no positional parameters, "$@"
              and $@ expand to nothing (i.e., they are removed).

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to calculate difference of split and sum the difference

In the awk I am trying to subtract the difference $3-$2 of each matching $4 before the first _ (underscore) and print that value in $13. I think the awk will do that, but added comments. What I am not sure off is how to add a line or lines that will add sum each matching $13 value and put it in... (2 Replies)
Discussion started by: cmccabe
2 Replies

2. Programming

what is the main difference between difference between using nonatomic lseek and O_APPEND

I think both write at the end of the file ...... but is there a sharp difference between those 2 instruction ..... thank you this is my 3rd question today forgive me :D (1 Reply)
Discussion started by: fwrlfo
1 Replies

3. Programming

mmap and malloc, whats the difference?

In what situations one would use malloc instead of mmap and vice versa. Both return a virtual addr ptr. So whats the difference? (4 Replies)
Discussion started by: dragonpoint
4 Replies

4. UNIX for Dummies Questions & Answers

Whats the difference between $status and $?

Hi, In linux we have exit status variable ($?) and status which tells whether last command was successfull or not. Can someone please tell me what is difference between both. Both tells whether command was successful or not, Any particular difference between them? Thanks in Advance. Thanks... (3 Replies)
Discussion started by: sarbjit
3 Replies

5. UNIX for Dummies Questions & Answers

whats the difference between zombie orpha and defunct processes

can some one please explain zombie orphan defunct and how they r related (3 Replies)
Discussion started by: pbsrinivas
3 Replies

6. UNIX for Dummies Questions & Answers

Linux OR Unix Whats The Difference!

What is the difference bettween linux and unix? Sorry but I am really new to this! :confused: Also are they BOTH free :-D (1 Reply)
Discussion started by: jamesthemagicia
1 Replies

7. What is on Your Mind?

Whats Behind Your Name?

Looking at the member list, there are alot of interesting names, some unique, some bizarre, and some that are just plain. How did you come by your name? Why did you choose your label? Me? Well, I wish I could change mine. I chose Google because thats how I stumbled upon this site. I wasn't sure... (66 Replies)
Discussion started by: google
66 Replies

8. Post Here to Contact Site Administrators and Moderators

Whats the go?

woofie, Your posts are being deleted because your use of profanity. I am close to changing your status to read only. In fact, if you argue with the mods again, I will ban you from these boards. Neo (1 Reply)
Discussion started by: Neo
1 Replies

9. UNIX for Dummies Questions & Answers

Whats the difference between...

the various distros of free Linux and other *nix OSes? I'm curious. (1 Reply)
Discussion started by: hype.it
1 Replies
Login or Register to Ask a Question