[net.unix] 2.8 Bourne shell question

jwp@uwmacc.UUCP (Jeffrey W Percival) (09/06/85)

I tried this litle shell script on my 2.8BSD Bourne shell:

	read word < foo
	echo $word

and it didn't do what I thought it would do.  The script waited
until I typed something on my keyboard, then it said "illegal io".
Is it possible to read from files?  Is this just a 2.8 bug?

	Thanks!

-- 
	Jeff Percival ...!uwvax!uwmacc!jwp

henry@utzoo.UUCP (Henry Spencer) (09/08/85)

> I tried this litle shell script on my 2.8BSD Bourne shell:
> 
> 	read word < foo
> 
> and it didn't do what I thought it would do...
> Is it possible to read from files?  Is this just a 2.8 bug?

It's a defect in old Bourne shells.  (I think it's documented, in fact;
look for something like "...except where specified no input output
redirection is permitted for [built-in] commands..." at the top of the
list of built-in commands.)  The more recent (SysV) shells have fixed this.
-- 
				Henry Spencer @ U of Toronto Zoology
				{allegra,ihnp4,linus,decvax}!utzoo!henry

mikeh@haddock.UUCP (09/08/85)

The Bell System III Bourne shell did not support io redirection
on builtins.  Perhaps this why the program `line' exists?
V.2 bourne shell does allow redirection on builtins.

rpw3@redwood.UUCP (Rob Warnock) (09/12/85)

+---------------
| > I tried this litle shell script on my 2.8BSD Bourne shell:
| > 	read word < foo
| > and it didn't do what I thought it would do...
| > Is it possible to read from files?  Is this just a 2.8 bug?
| It's a defect in old Bourne shells... recent (SysV) shells have fixed this.
| Henry Spencer @ U of Toronto Zoology {allegra,ihnp4,linus,decvax}!utzoo!henry
+---------------

Another "quick hack" I have seen for this is:

	word=`head foo`

If you don't have "head", you can write it easily enough, or use (*gag*):

	word=`(read junk; echo \$junk) < foo`


Rob Warnock
Systems Architecture Consultant

UUCP:	{ihnp4,ucbvax!dual}!fortune!redwood!rpw3
DDD:	(415)572-2607
USPS:	510 Trinidad Lane, Foster City, CA  94404

fbp@cybvax0.UUCP (Rick Peralta) (09/17/85)

>
>> I tried this litle shell script on my 2.8BSD Bourne shell:
>> 	read word < foo
>> and it didn't do what I thought it would do...
>> Is it possible to read from files?  Is this just a 2.8 bug?
>It's a defect in old Bourne shells... recent (SysV) shells have fixed this.
>Henry Spencer @ U of Toronto Zoology {allegra,ihnp4,linus,decvax}!utzoo!henry
>
YAH (Yet Another Hack) would be to:

	a=`cat file`
	echo $a


Rick  ...!cybvax0[!dmc0]!fbp

"A likely story.  I don't believe a word of it."