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

Burton Strauss Burton_Strauss at comcast.net
Tue Dec 6 16:59:13 CST 2005


continue and break both work in bash loops like the do in C/C++/Java...
-----Burton

-----Original Message-----
From: discuss-bounces at ntlug.org [mailto:discuss-bounces at ntlug.org] On Behalf
Of Eric Schnoebelen
Sent: Tuesday, December 06, 2005 4:31 PM
To: NTLUG Discussion List
Subject: Re: [NTLUG:Discuss] for loop - bash scripting.. 


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"

_______________________________________________
https://ntlug.org/mailman/listinfo/discuss





More information about the Discuss mailing list