Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!amdahl!pacbell!sactoh0!tree!stever From: stever@tree.UUCP (Steve Rudek) Newsgroups: comp.unix.questions Subject: Re: Help with strings in Bourne shell Summary: Questions on this file descriptor "slight of hand" Message-ID: <275@tree.UUCP> Date: 27 Apr 89 20:20:53 GMT References: <10166@orstcs.CS.ORST.EDU> <1493@vsedev.VSE.COM> <870@marvin.Solbourne.COM> Distribution: usa Organization: TREE BBS (916)-349-0385 Sacramento, Ca Lines: 36 In article <870@marvin.Solbourne.COM>, dce@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