Red Hat Bugzilla – Bug 19747
Bash's builtin function "read" does not set the variable
Last modified: 2007-04-18 12:29:29 EDT
The bash builtin function read doesn't seem to work. Consider the
A configuration file named "serv.conf" that contains:
Suppose we want to grab the TOPMS_UNIT value, which is 840. In a script
(or at the command line) we type
grep BASE_UNIT= serv.conf | sed 's/BASE_UNIT=//' | read UNIT
then we issue
UNIT contains "nothing", but should contain 840.
Instead of using "read" one can set the variable UNIT as follows:
UNIT=`grep BASE_UNIT= serv.conf | sed 's/BASE_UNIT=//'`
which will show the correct value was set (840)
grep TOPMS_UNIT= serv.conf | sed 's/TOPMS_UNIT=//' | read UNIT
? Or is that what you were doing?
Yes, that is what I meant.
I went back and retested to make sure I didn't pull a Homer. In my examples
where I say "BASE_UNIT=" I meant to say "TOPMS_UNIT".
If you're going to mark the MR as "Resolved, notabug" shouldn't you at least
explain yourself. I have scripts that used to work in previous Redhat releases
that are now failing because of this. Why is this NOTABUG?
I misunderstood and thought that your original script was in error.
But this is what the Single UNIX spec says:
"Some systems have implemented the last stage of a pipeline in the current
environment so that commands such as:
command | read foo
set variable foo in the current environment. This extension is allowed, but not
required; therefore, a shell programmer should consider a pipeline to be in a
subshell environment, but not depend on it."
And 'man bash' (line 277) says:
"Each command in a pipeline is executed as a separate process (i.e., in a
So it isn't really a bug in bash, as far as I can see.
It isnt a bash bug
foo|bar| (read A; echo $A)
I agree that this MR should be closed as NOTABUG.
The example given above works to set a variable in the current shell to the
value expected. The coding is different, but it works.
*** Bug 20564 has been marked as a duplicate of this bug. ***
*** Bug 21902 has been marked as a duplicate of this bug. ***
*** Bug 42282 has been marked as a duplicate of this bug. ***
*** Bug 59222 has been marked as a duplicate of this bug. ***