Welcome to Soft32 Linux Forums!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

$@ and $* and IFS

 
   Soft32 Home -> Linux -> General Discussions RSS
Next:  [PATCH] Add in_execve flag into task_struct.  
Author Message
iceman19860106

External


Since: Jan 03, 2009
Posts: 3



(Msg. 1) Posted: Mon Jan 05, 2009 9:52 pm
Post subject: $@ and $* and IFS
Archived from groups: linux>redhat (more info?)

I write a shell program named "t1.sh" on below:

#!/bin/bash
IFS=*
echo "$*"
echo "$@"

type:
../t1.sh a b c

result:
a*b*c
a b c

now i change the program as below:
#!/bin/bash
IFS=*
echo $*
echo $@

type:
../t1.sh a b c

result:
a b c
a b c

why the $* should be add "" so that it can display the right format
whereas $@ not be?
Back to top
Login to vote
iceman19860106

External


Since: Jan 03, 2009
Posts: 3



(Msg. 2) Posted: Wed Jan 07, 2009 2:04 am
Post subject: Re: $@ and $* and IFS [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

anybody help??
Back to top
Login to vote
Johnny Rebel

External


Since: Jan 05, 2009
Posts: 6



(Msg. 3) Posted: Wed Jan 07, 2009 7:01 pm
Post subject: Re: $@ and $* and IFS [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

iceman19860106 wrote:
> anybody help??

Clipped from here:
http://www.mpi-inf.mpg.de/~uwe/lehre/unixffb/quoting-guide.html

See section 3.1.7 if going there.

<snip>
In the Bourne shell, the positional parameters (or command line
arguments) can be accessed individually as $1, $2, ... . To access the
whole list of positional parameters, the two special parameters $* and
$@ are available. Outside of double quotes, these two are equivalent:
Both expand to the list of positional parameters starting with $1
(separated by spaces). Within double quotes, however, they differ: $*
within a pair of double quotes is equivalent to the list of positional
parameters, separated by quoted spaces, i.e., "$1 $2 ...". On the other
hand, $@ within a pair of double quotes is equivalent to the list of
positional parameters, separated by unquoted spaces, i.e., "$1" "$2"
..... (This is the behaviour if $IFS has its default value (space, tab,
newline). If $IFS has a non-standard value, the evaluation of $*, $@,
"$*", and "$@" is highly obscure, non-intuitive, badly documented, and
varying between different shells. Avoid it.)

What happens if the list of positional parameters is empty (i.e., $#
equals 0)? As one should expect, $* and $@ expand to nothing and "$*"
expands to one empty argument. The question is: what should "$@" be?
Originally, it expanded to one empty argument, just as "$*". But this is
somewhat inconsistent: it contradicts the usual rule that "$@" yields
exactly the list of all positional parameters originally passed to the
current program, i.e., a list whose length equals $#. (See Sect. 3.1.8
for a fix.) In most Bourne shells used today, the evaluation of "$@" has
been regularized, so that "$@" behaves in the way a programmer expects:
it expands to the list of all positional parameters, and in particular
it is expands to nothing if the list of positional parameters is empty.
<snip>



--


--> GNU/Linux is user friendly... it's just picky about its friends.
Back to top
Login to vote
Display posts from previous:   
Related Topics:
disk cleanup - Hi all, I installed RH8.0 with including all the options (everything) on an 8 gig partition. I've been doing up2date..

Cannot start x config in Mandrake 9.1 - I disabled auto-start up into a GUI like KDE So now I am at the command prompt [root@hostname /]# I type ..

Where to discuss Ximian? - I have Red Hat 9 and Ximian Desktop 2. A few issues have come up, but I'm not sure of the best group to post to. Any....

Move directories to different drive -- How?? - System: Compaq PC with 6GB hard drive RedHat 9 Linux Hard drive chopped into 3 Primary and 1 Extended partitions...

[MC-LUUG] Upcoming Installfest - The second monthly MC-LUUG (McMinnville Linux and Unix Users Group) installfest is slated for 12 July 2003 in..

Linux modems - Are there any modems which work woth both LInux and Windows. How easy is it to find one.
       Soft32 Home -> Linux -> General Discussions All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Categories:
 Windows
  Linux
 Mac
 PDA


[ Contact us | Terms of Service/Privacy Policy ]