Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 31 Dec 2004 10:36:24 +0100
From:      Olivier Gautherot <olivier@gautherot.net>
To:        Tom Huppi <thuppi@huppi.com>
Cc:        freebsd-newbies@freebsd.org
Subject:   Re: Shell Games
Message-ID:  <41D51D98.7010006@gautherot.net>
In-Reply-To: <Pine.BSF.4.58.0412310336440.39721@nuumen.pair.com>
References:  <49B5BEF2.7CCF22F4.0F75C5EC@netscape.net> <1104458982.622.3.camel@chaucer> <F2007F7E-5AD6-11D9-BAFF-000D932D61F0@ohko.org> <afa60d2404123100235580cb3f@mail.gmail.com> <Pine.BSF.4.58.0412310336440.39721@nuumen.pair.com>

next in thread | previous in thread | raw e-mail | index | archive | help
Hi folks!

>>>FWIW, I've always used 'tcsh' interactively, but almost switched a
>>>while back out of disgust at not being able to figure out how to
>>>get a one-line foreach/{do_something}/end loop (which would allow
>>>me to re-run a complex command easily.)
>>>      
>>>
>>I would recommend 'ksh' it does the tasks of both 'csh' and 'sh' with
>>advanced programming features, check out http://www.kornshell.com/
>>    
>>
>
>As it happens, my attempts to do this one-liner with 'tcsh' were a
>direct result of watching someone who used 'ksh'.  I thought it
>probable that 'bash' also could accomplish this feat (and maybe
>'tcsh' also if I could figure it out.)  Anyone know?
>  
>
The keyword is "for", not "foreach". Try:

bash-2.05b$ for n in tata tete titi toto tutu ; do echo "New item" ; 
echo $n ; done
New item
tata
New item
tete
New item
titi
New item
toto
New item
tutu
bash-2.05b$

Note that the "do" must be followed directly by a command. A semicolon
(i.e. an empty command) is considered a syntax error.

My cent worth ;-)
    Olivier



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?41D51D98.7010006>