Bugzilla will be upgraded to version 5.0 on December 2, 2018. The outage period for the upgrade will start at 0:00 UTC and have a duration of 12 hours
Bug 71586 - read does not take input frmo a pipe
read does not take input frmo a pipe
Product: Red Hat Linux
Classification: Retired
Component: bash (Show other bugs)
i686 Linux
medium Severity medium
: ---
: ---
Assigned To: wdovlrrw
Ben Levenson
Depends On:
  Show dependency treegraph
Reported: 2002-08-15 09:35 EDT by David Stevenson
Modified: 2007-04-18 12:45 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2002-08-15 09:35:09 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description David Stevenson 2002-08-15 09:35:05 EDT
From Bugzilla Helper:
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 4.0; Q312461)

Description of problem:
if I do 'echo hello | read line' nothing goes into $line in bash.  It works 
(and has always worked) in ksh.  The man page suggests that it should work 
because it is taking it frmo the standard input.

Version-Release number of selected component (if applicable):

How reproducible:

Steps to Reproduce:
1.unset line
1.echo hello | read line
2.echo $line

Actual Results:  nothing ($line is empty)

Expected Results:  'hello' should be returned

Additional info:

This works in the korn shell on every type of unix I have tried.  I would also 
expect it to work in bash as it is better!
Comment 1 Bernhard Rosenkraenzer 2002-08-15 09:46:26 EDT
This is actually the correct behavior. 
The part of the command after the pipe ("read", in this case) is executed in a 
different process space, so the variable isn't available to the originally 
calling shell. 
You _can_ do: 
whatever |while read a; do echo $a; done 
(because the echo is in the same process space as the read) 
You _can't_ do: 
whatever |read a 
echo $a 
(because the echo is in the same process space as "whatever", but not as 
echo foo |read a && echo $a 
Won't work, but 
echo foo |(read a && echo $a) 
Comment 2 David Stevenson 2002-08-15 11:04:55 EDT
Yes, fair enough.  This is the difference between sh and ksh is it not, that 
ksh spawns children differently, so echo hello | read line will work because it 
passes it's environment down differently.  I assume that bash behaves like sh 
because it is a bourne again shell not a bourne again korn shell ;-)

My problem was that I was porting a shell script from a Sequent (ksh) to a 
linux machine (bash) and found that the command I had been using for years 
didn't work.  I have just revamped the script a bit and all is well.

(Mind you - I've just noticed that it doesn't work in the RH7.2 ksh either - it 
does in the PTX and SOlaris 5.8 ksh's)

Anyway, thanks for the explanation and your help.


Note You need to log in before you can comment on or make changes to this bug.