LINUX.IE, website of the Irish Linux Users' Group
Tux rules!

   
Home
New Users
Articles
Download
Projects
Community
Vendors

  Print Version
 
Archives:


planetILUG

Recent News

News Archive


Join the
ILUG
on FaceBook


Join the
ILUG
on LinkedIn


Join the
ILUG SETI
Group



















 
 :: Mailing Lists

[ILUG] alias

[ILUG] alias

Philip Reynolds phil at redbrick.dcu.ie
Thu Mar 14 12:08:05 GMT 2002


kevin lyda's [kevin at suberic.net] 70 lines of wisdom included:
> according to the sh man page:
> 
>     *   Expands to the positional parameters, starting from
> 	one.   When  the  expansion  occurs  within  double
> 	quotes,  it expands to a single 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 null or unset, the parameters are  separated  by
> 	spaces.
>     @   Expands to the positional parameters, starting from
> 	one.   When  the  expansion  occurs  within  double
> 	quotes,  each parameter expands as 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).
> 
> any shell scripting gurus have comments on this?  i've been kind of
> curious since i read it.

I'm not sure if you're having trouble understanding what the manpage
means, so I'll give an explanation and if I'm being patronising by
assuming you don't, I apologise :)
I would in no way call myself a shell scripting guru either.

This is my general assumption of using both:

$* is, for want of a better term, like a string, it's just a string
which each parameter separated by IFS (if IFS is null or unset like
the manpage says, the separator is a space)

$@ is like an array, IFS makes no difference. If you want to loop
through the arguments.

Basically, if you just want to print all the arguments or use IFS,
then $* is fine. $@ is handier when you want to handle each argument
separately.

This is at least my understanding.

Regards,
Phil.




More information about the ILUG mailing list
Read this without the formatting.
                                                                                                    

 

Hosted by HEAnet


Maintained by the ILUG website team. The aim of Linux.ie is to support and help commercial and private users of Linux in Ireland. You can display ILUG news in your own webpages, read backend information to find out how. Networking services kindly provided by HEAnet, server kindly donated by Dell. Linux is a trademark of Linus Torvalds, used with permission. No penguins were harmed in the production or maintenance of this highly praised website. Looking for the Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!
RSS Version
Powered by Dell