PROBLEM: The bash builtin function read doesn't seem to work. Consider the following: A configuration file named "serv.conf" that contains: BASE_DIR=/usr/topms TOPMS_BIN=bin TOPMS_UNIT=840 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 echo $UNIT UNIT contains "nothing", but should contain 840. WORK-AROUND: Instead of using "read" one can set the variable UNIT as follows: UNIT=`grep BASE_UNIT= serv.conf | sed 's/BASE_UNIT=//'` the issue echo $UNIT which will show the correct value was set (840)
What about: grep TOPMS_UNIT= serv.conf | sed 's/TOPMS_UNIT=//' | read UNIT ? Or is that what you were doing?
Oh Jesus, 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". Sorry McNaul
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? McNaul
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 subshell)." So it isn't really a bug in bash, as far as I can see.
It isnt a bash bug do 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. Dan McNaul
*** 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. ***