Help with strings in Bourne shell

Steve Rudek stever at tree.UUCP
Fri Apr 28 06:20:53 AEST 1989


In article <870 at marvin.Solbourne.COM>, dce at Solbourne.COM (David Elliott) writes:
> 	exec 3<&0 0<"$INPUTFILE"
> 	while read DEFINITION
> 	do
> 		echo "$DEFINITION"
> 	done
> 	exec 0<&3
> 
> The first exec makes fd 3 a duplicate of fd 0 (stdin), and
> redirects stdin.  The second exec changes fd 0 back to what
> it was.
I've never seen anything quite like this.  It is beautiful, exciting and
rather bizarre; shell at its best! :-) I can guess that you're creating
a file descriptor 3 *strictly* to preserve the (address??) of stdin.  But the
0<"$INPUTFILE" bit boggles my mind.  How is this different from just <$INPUTFILE
I guess the leading "exec" is important in understanding this?  Could you
explain?

By the way, how would:
  while read DEFINITION <$INPUTFILE 
  do
  done

differ from: 
  while read DEFINITION
  do
  done <$INPUTFILE

Or wouldn't it?


If not too much trouble, I'd appreciate a *copy* of any responses via email
since I really have a considerable interest in the answer and fear I might
otherwise miss a newsgroup response.
----------
Steve Rudek  {ucbvax!ucdavis!csusac OR ames!pacbell!sactoh0} !tree!stever



More information about the Comp.unix.questions mailing list