scripting

Jason Kircher cdrradar at speakeasy.net
Mon Jul 12 12:05:08 PDT 2004


On Monday 12 July 2004 13:57, Shane Shields wrote:
> On Monday 12 July 2004 7:40 am, Jason Kircher wrote:
> > On Sunday 11 July 2004 23:51, Shane Shields wrote:
> > I'm one for readability, even if it's a touch lengthy.
> >
> > for $i in {'file 1', 'James Kirk', 'Spock', 'Leonard McCoy'} ; do
>
> How can that be more readable? There is more margin for typo's too.....
> Just tried it. That doesn't work.
>
> locutus:~$ for $i in {'file 1', 'James Kirk', 'Spock', 'Leonard McCoy'} ;
> do echo $i;done
> bash: `$i': not a valid identifier
>
> The variable in the for statement can't have a $ in front of it because it
> is being assigned a value.
>
> However this does but does not give the required results.
>
> locutus:~$ for i in {'file 1', 'James Kirk', 'Spock', 'Leonard McCoy'} ; do
> echo $i;done
> {file 1,
> James Kirk,
> Spock,
> Leonard McCoy}
>
> This does give the required results.
>
> locutus:~$ for i in 'file 1' 'James Kirk' 'Spock' 'Leonard McCoy' ; do echo
> $i;done
> file 1
> James Kirk
> Spock
> Leonard McCoy
>
> As bash uses space seperation (or whatever the IFS is set at) the brackets
> and comma's are considered part of the word.
> --
> Shane Shields

YEEK!  Uuh...  *slams head through desk* *puts on dunce hat*  My bad.  It's 
when I pull stunts like the following that I stick in braces...

for i in file.{1,2,3,4} ; do echo $i ; done

Now I know that in that you can subsitute `seq 1 4`, but...  A little more 
bashfu for everyone!  :D
-- 
Anyone sending unwanted advertising e-mail to this address will be charged a 
$25 fee for network traffic and computing time.  By extracting my address 
from this message, its header, or any web site showing my email address 
either in literal or aggregate form, you agree to these terms.




More information about the lfs-chat mailing list