[NTLUG:Discuss] for loop - bash scripting..

Eric Schnoebelen eric at cirr.com
Tue Dec 6 16:30:51 CST 2005


Richard Geoffrion writes:
- how do you end an $INSTANCE in a for/loop without killing the entire loop?

	Not entirely sure what you're asking for.. My
interpretation is: How do I bail out of a loop before completing
interation over all the for loops possible values?

	Answer: break;

	Example:

		#!/bin/sh
		for i in "$@"; do
		    if [ ! -d $i ] ; then
			echo "not a directory"
			break
		    fi
		    # other processing here
		done

	The above loops over the  argument list ($@) and bails
out of the loop if any of the artuments are not a directory.
(more intresting in the above case is ``continue'', which would
restart the for loop with the next argument value.)

--
Eric Schnoebelen		eric at cirr.com		http://www.cirr.com
			"/bin/sh: Bourne in the USA"




More information about the Discuss mailing list