Help bourne shell problem on sun and bsd

Christopher J. Hawley chawley at sundiver.esd.sgi.com
Fri Jun 7 10:44:35 AEST 1991


    In article <3089 at cod.NOSC.MIL>, medin at 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	<std_disclaimer.h>
      /*  SGI delivers mail, but I write the opinions contained herein. */
---
    Christopher J. Hawley / esper               chawley at 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."



More information about the Comp.unix.questions mailing list