[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Shell Scripting Question



On Tue, Oct 30, 2001 at 06:48:42PM -0500, Sunny Dubey wrote:

> for $fruit in `cat /usr/fruits.txt` ; 
> 	do
> 		echo -n "Do you like $fruit"
> 		read ANS
> 		if [ -z $ANS ] ; then
> 		# NEED HELP WITH CODE HERE
> 		fi
> 	done
> 
> how can I be able to have loop repeat itself at the same iteration when the 
> "if -z" statement turns out to be ture??
> 
> I know that continue can be used to do this, however from my understanding 
> you need to tell it at which iteration you want to start at.  Is there a 
> dynamic way of doing this or something??
> 
> thanks so much for any info you can give.

I assume fruits.txt is line separated?  In that case, you want

cat /usr/fruits.txt | \
while read fruit ; do
	echo -n "Do you like $fruit? "
	unset ANS
	while [ -z "$ANS" ] ; do
		read ANS
	done
	# do something with answer
done

Jonathan
-- 
Jonathan B. Leffert <jonathan@leffert.net> | "So now, less than five
years later, you can go up on a steep hill in Las Vegas and look West, and
with the right kind of eyes you can almost see the high-water mark, that
place where the wave finally broke and rolled back." -- Hunter S. Thompson



Reply to: