Path: utzoo!attcan!uunet!tut.cis.ohio-state.edu!ucbvax!hplabs!hpda!hpdslab!hp-ptp!jim
From: jim@hp-ptp.HP.COM (James_Rogers)
Newsgroups: comp.unix.questions
Subject: Re: Bourne Shell FOR loop confusion
Message-ID: <1730003@hp-ptp.HP.COM>
Date: 16 Aug 89 17:40:59 GMT
References: <689@msa3b.UUCP>
Organization: HP Pacific Technology Park - Sunnyvale, Ca.
Lines: 39

/ hp-ptp:comp.unix.questions / kevin@msa3b.UUCP (Kevin P. Kleinfelter) /  6:16 am  Aug  1, 1989 /
>What I really want to do is to redirect input to "read", but read is
>non-redirectable (according to my doc, and experience on my system).
>I was going to attemtpt this as follows
>
>   for i in 1
>   do
>      read a b c
>   done < /tmp/foo
>
>If I "echo a, b, c" inside the loop, I get the expected values from the file.
>If I "echo a, b, c" after the loop, I see that they have reverted to their
>values prior to the loop.

You could try the following form of redirection:

for nextfile in a b c
do
	cat $nextfile | {
		while [ -r $nextfile ]
		do
			read aline
			if [ $? -ne 0 ]
			then
				break
			fi
			echo $aline
		done
	}
done


I know that this is not pretty, but it does allow you to read through
files a, b, and c from the Bourne shell.



Jim Rogers  at Hewlett Packard Industrial Applications Center
	       Sunnyvale, California