Solaris '/usr/bin/read' not reading?

Solaris '/usr/bin/read' not reading?

Post by anonym.. » Tue, 28 Aug 2001 21:31:57



Dear all,

  The read man page on this Solaris 8 box says,

NAME
     read - read a line from standard input

but it only seems to work from terminal, not via
pipe-line:

$ /bin/sh        
$ echo 1 | read A
$ echo $A

$ which read
/usr/bin/read
$ uname -a
SunOS [hostname] 5.8 Generic_108528-09 sun4u sparc SUNW,Ultra-2
$ read A
1
$ echo $A
1
$

  Could someone clarify please what is happening here?

Thanks,
Aleksey Tsalolikhin

P.S. Same behaviour on a Solaris 2.6 box.

 
 
 

Solaris '/usr/bin/read' not reading?

Post by Akop Pogosia » Tue, 28 Aug 2001 21:59:33



> Dear all,
>   The read man page on this Solaris 8 box says,
> NAME
>      read - read a line from standard input
> but it only seems to work from terminal, not via
> pipe-line:
> $ /bin/sh        
> $ echo 1 | read A
> $ echo $A
> $ which read
> /usr/bin/read
> $ uname -a
> SunOS [hostname] 5.8 Generic_108528-09 sun4u sparc SUNW,Ultra-2
> $ read A
> 1
> $ echo $A
> 1
> $
>   Could someone clarify please what is happening here?

/usr/bin/read can't and does not work because it is being run as a
separate process, and therefure, can't modify your shell's
environment. All shells implement it as a built-in function.  There
was an amusing discussion on why /usr/bin/read exists on this news
group recently.

As for using "read" to read the variable from a pipe, that might not
work the way you do it because my understanding is that most or all
shells execute the commands in a pipeline from a separate
subprocesses.  So

echo 1 | read X; echo $X

will not work but

echo 1 | ( read X; echo $X)

works.

--
Akop Pogosian

BugID 4137237: patchadd 106300-01 results in rm -rf / as root