Xref: utzoo comp.unix.questions:32004 comp.unix.shell:2358 Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!mips!sgi!shinobu!odin!sundiver.esd.sgi.com!chawley From: chawley@sundiver.esd.sgi.com (Christopher J. Hawley) Newsgroups: comp.unix.questions,comp.unix.shell Subject: Re: Help bourne shell problem on sun and bsd Keywords: builtin, redirection, loop, bourne shell Message-ID: <1991Jun7.004435.16257@odin.corp.sgi.com> Date: 7 Jun 91 00:44:35 GMT References: <3089@cod.NOSC.MIL> Sender: news@odin.corp.sgi.com (Net News) Reply-To: chawley@sundiver.esd.sgi.com Distribution: usa Organization: Silicon Graphics, Inc. / Personal Systems Division Lines: 56 In article <3089@cod.NOSC.MIL>, medin@cod.nosc.mil (Ted Medin) writes: |> When using the bourne shell: |> |> pwd > temp |> read dir < temp |> |> Just hangs until you type something on the keyboard when using bsd 4.3. |> However on a sun machine it works fine, the variable dir gets the current |> working directory. |> Is "read" keyboard input only or ????? From The UNIX Programming Environment, Kernighan & Pike, pp. 159-160: -------------------------------- " read can only read from the standard input; it can't even be redirected. None of the shell built-in commands (as opposed to the control flow primitives like for ) can be redirected with > or < : [example omitted] "This might be described as a bug in the shell, but it is a fact of life. Fortunately, it can usually be circumvented by redirecting the loop surrounding the read . This is the key to our implementation of the pick command: " [example of shell command pick omitted] So, in any environment (with the dubious exception of Sun's), you can say for foo in dummy do read dir done < temp with the desired results. Any of the control flow primitives can be used to achieve the same effect... while : ; do read dir; break; done < temp is another way to get what you want. For the curious: what version of Sun software are you running which has the sh behaviour you describe? #include /* SGI delivers mail, but I write the opinions contained herein. */ --- Christopher J. Hawley / esper chawley@sundiver.esd.sgi.com Silicon Graphics, Inc. 1L-945 phone: 415 / 335-1621 Mountain View, CA 94039-7311 USA 408 / 243-1042 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "Nicht nur wie schnell Sie fahren, sondern _wie_ Sie schnell fahren."