[comp.sys.pyramid] read bug in 4.4 /bin/sh?

era@NIWOT.UCAR.EDU (03/21/89)

Does anybody out there know what i/o redirection with the
Bourne shell's read command is *supposed* to do?

The following shell script reads the first word from itself
into the variable x and echoes it under SunOS 4.0.  However,
it hangs under OSx4.4 and Ultrix 2.2; if you type a line at
it while it's hung, it belches out "$0: illegal io".  Anybody
know who's "right"?
--------
#!/bin/sh
read x < $0
echo x = $x
--------

Ed Arnold, NCAR
era@ncar.ucar.edu

era@NIWOT.UCAR.EDU (03/21/89)

Oooops ... please disregard my previous msg on this subject.
Sure nuff, it's one of those 4.x vs. S/V issues.

csg@pyramid.pyramid.com (Carl S. Gutekunst) (03/21/89)

In article <8903201700.AA00197@era.ucar.edu.UCAR.EDU> era@NIWOT.UCAR.EDU writes:
>#!/bin/sh
>read x < $0
>echo x = $x

Redirection of the "read" command is not supported in the 4.3BSD Bourne shell;
it is supported in the System V Bourne shell. So, this works on SunOS and the
Pyramid's att universe, but does not on Ultrix or the Pyramid's ucb universe.

You can do what you want -- better I think -- using head(1):

	#!/bin/sh
	x=`head -1 $0`
	echo x = $x

<csg>