Bug 71586
Summary: | read does not take input frmo a pipe | ||
---|---|---|---|
Product: | [Retired] Red Hat Linux | Reporter: | David Stevenson <d.j.stevenson> |
Component: | bash | Assignee: | wdovlrrw <brosenkr> |
Status: | CLOSED NOTABUG | QA Contact: | Ben Levenson <benl> |
Severity: | medium | Docs Contact: | |
Priority: | medium | ||
Version: | 7.2 | ||
Target Milestone: | --- | ||
Target Release: | --- | ||
Hardware: | i686 | ||
OS: | Linux | ||
Whiteboard: | |||
Fixed In Version: | Doc Type: | Bug Fix | |
Doc Text: | Story Points: | --- | |
Clone Of: | Environment: | ||
Last Closed: | 2002-08-15 13:35:09 UTC | Type: | --- |
Regression: | --- | Mount Type: | --- |
Documentation: | --- | CRM: | |
Verified Versions: | Category: | --- | |
oVirt Team: | --- | RHEL 7.3 requirements from Atomic Host: | |
Cloudforms Team: | --- | Target Upstream Version: | |
Embargoed: |
Description
David Stevenson
2002-08-15 13:35:05 UTC
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 "read"). Similarily: echo foo |read a && echo $a Won't work, but echo foo |(read a && echo $a) will. 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. David |