Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!ncar!gatech!udel!princeton!phoenix.Princeton.EDU!pfalstad From: pfalstad@phoenix.Princeton.EDU (Paul Falstad) Newsgroups: comp.unix.questions Subject: Re: Bourne to read? Keywords: Bourne read Message-ID: <6746@idunno.Princeton.EDU> Date: 1 Mar 91 05:41:18 GMT References: <1991Feb28.160948.24987@hoss.unl.edu> Sender: news@idunno.Princeton.EDU Distribution: na Organization: The Royal Society For Putting Things On Top Of Other Things Lines: 24 mosemann@sardion.unl.edu (Russell Mosemann) wrote: > In the Bourne shell, why does this not work > echo words | read W > but this does (if I put the words in the file) > read W < file This is in the FAQ, although somewhat buried. Basically, the pipe forces read into a subshell in the first case. sh spawns a subshell to simplify file descriptor handling for the pipe; the subshell then reads its input into the variable W, and then exits. The parent shell's W is not changed. In the second (simpler) case, read is executed in the main shell. In some versions of sh (evidently not in SunOS), as well as in ksh (I think) and in another shell whose name escapes me at the moment, "echo words | read W" will return the expected result. I don't know of any nice way around this. If you can, redirect the output to a file, and then do "read W