LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-18-2006, 10:44 AM   #1
johnny_jiang
LQ Newbie
 
Registered: Feb 2006
Posts: 2

Rep: Reputation: 0
The differece between $@ and $*


Hello,everyone

I'm a linux newbie from Shanghai.There's a question regarding $@ and $* which has confused me for a long time.Actually I have read the bash manual and some bibliographies,I found that they just talk about these two positional parameters' difference when they're double quoted.So what if they're assigned to a variable?
I've done some tests below.

Code:
set -- "First Arg" "Second" "Third:Arg" "" "Fifth: :Arg"

IFS=:

var=$@
var1=$*

echo "$var"  # First Arg Second Third Arg  Fifth   Arg
echo "$var1" # First Arg:Second:Third:Arg::Fifth: :Arg

IFS=

var=$@
var1=$*

echo "$var"  # First Arg Second Third:Arg  Fifth: :Arg
echo "$var1" # First Arg Second Third:Arg   FFiifftthh::  ::AArrg
It's too weird for me to understand.

Last edited by johnny_jiang; 02-18-2006 at 10:55 AM.
 
Old 02-18-2006, 12:42 PM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,332
Blog Entries: 55

Rep: Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533
I'm a linux newbie from Shanghai.
Doesn't mean nothing, Im a noob from Hell when it comes to open heart surgery :-]


AFAIK \* is the concatenation (whole string) while @ the IFS-sep'ped parts:

]$ tellMeIWannaKnow() { i=("$*"); echo ${#i[@]}; }
]$ tellMeIWannaKnow onetwothree four
1

]$ tellMeIWannaKnow() { i=("$@"); echo ${#i[@]}; }
]$ tellMeIWannaKnow onetwothree four
2
 
Old 02-18-2006, 11:51 PM   #3
johnny_jiang
LQ Newbie
 
Registered: Feb 2006
Posts: 2

Original Poster
Rep: Reputation: 0
Thank you,unSpawn!

I understand what you're talking about."$@" will seperate arguments with IFS.But there's one thing I am also a little fuzzy on it.

Code:
var=$@

echo "$var"  # First Arg Second Third Arg  Fifth   Arg
How to explain how that runs?Why do the colons disappear?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
whats the differece killi Linux - Software 2 04-26-2003 07:29 AM
Differece between Lilo and Grub r4merlin Linux - General 1 02-17-2003 02:40 AM


All times are GMT -5. The time now is 03:25 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration