Help with strings in Bourne shell

Wm. E. Davidsen Jr davidsen at steinmetz.ge.com
Wed May 3 03:05:56 AEST 1989


In article <275 at tree.UUCP> stever at tree.UUCP (Steve Rudek) writes:

| By the way, how would:
|   while read DEFINITION <$INPUTFILE 
|   do
|   done
| 
| differ from: 
|   while read DEFINITION
|   do
|   done <$INPUTFILE
| 
| Or wouldn't it?

  Redirection on the read command would open and read the INPUTFILE
every time throught the loop (ie. read 1st line forever). On the done
line the redirect causes all commands in the loop to read their stdin
from INPUTFILE.

  If you want to read successive lines from a file and process them, but
not redirect stdin, here's a technique (I invented it myself, but I
doubt that it's unique).

	while read name 0<&3
	do
	  : whatever here
	  : stdin is still tty
	done 3< $INPUTFILE

  This works with SysV sh as well as ksh (I didn't try BSD, sorry).
-- 
	bill davidsen		(wedu at crd.GE.COM)
  {uunet | philabs}!steinmetz!crdos1!davidsen
"Stupidity, like virtue, is its own reward" -me



More information about the Comp.unix.questions mailing list