[NTLUG:Discuss] for loop - bash scripting..
Fred James
fredjame at fredjame.cnc.net
Tue Dec 6 16:27:13 CST 2005
Richard Geoffrion wrote:
> how do you end an $INSTANCE in a for/loop without killing the entire
> loop?
>
> -------------
> for INSTANCE in *.csv ; do
> if [ ! "$NAME" -a "EMAIL" ] ; then
> echo This record is not valid, ending the parsing process of
> this file.
> ;exit 65 done #even if this done is inside an succesful
> test condition, bash still sees it as a done.
> fi
>
> #rest of the .csv file parsing that requires ALL the parameters
>
>
> done
> -------------
Richard Geoffrion
I believe the simplest general form would be
for i in list
do
if test whatever
then
do this
else
continue
fi
other_stuff
done
[from the 'man' page for BASH]
continue [n]
Resume the next iteration of the enclosing for, while,
until, or
select loop. If n is specified, resume at the nth
enclosing
loop. n must be >= 1. If n is greater than the
number of
enclosing loops, the last enclosing loop (the
``top-level''
loop) is resumed. The return value is 0 unless the shell
is not
executing a loop when continue is executed.
Hope this helps
Regards
Fred James
>
More information about the Discuss
mailing list