why $* ?
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Shell > why $* ?




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    why $* ?  
yusuf


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-16-06 01:48 AM

Can someone please tell me why is the $* there in the following
example:

awk -F, '{
print $4 ", " $0
}' $*






[ Post a follow-up to this message ]



    Re: why $* ?  
Janis Papanagnou


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-16-06 01:48 AM

yusuf wrote:
> Can someone please tell me why is the $* there in the following
> example:
>
> awk -F, '{
> 	print $4 ", " $0
> 	}' $*
>

The $* expands on shell level to a list of words that has been
passed to the script containing these lines.

Say, these lines are in a script called 'mysript' and the script
is called this way...

myscript a b "c d" e

then within the shell program myscript it expands to...

awk -F, '{
print $4 ", " $0
}' a b c d e

The arguments a, b, c, d, e are then taken as the input data files
for the awk program.

The input files contain likely comma separated values (the "-F,").

Mind a couple things...
$4 and $0 are variables within awk
$* is a predefined shell variable
$* will split arguments that contain spaces (like "c d"); use the
quoted "$@" variable if you want it expanded as it has been passed


Janis





[ Post a follow-up to this message ]



    Re: why $* ?  
Bill Marcum


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-16-06 10:53 PM

On 15 Mar 2006 16:52:36 -0800, yusuf
<yusufm@gmail.com> wrote:
> Can someone please tell me why is the $* there in the following
> example:
>
> awk -F, '{
> 	print $4 ", " $0
> 	}' $*
>

Because the script writer didn't know to use "$@".


--
leverage, n.:
Even if someone doesn't care what the world thinks
about them, they always hope their mother doesn't find out.





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 03:29 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register