This service will be undergoing maintenance at 20:00 UTC, 2017-04-03. It is expected to last about 30 minutes
Bug 20564 - read builtin corrupts parameter assignment in loop
read builtin corrupts parameter assignment in loop
Status: CLOSED DUPLICATE of bug 19747
Product: Red Hat Linux
Classification: Retired
Component: bash (Show other bugs)
6.2
i386 Linux
medium Severity medium
: ---
: ---
Assigned To: Bernhard Rosenkraenzer
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2000-11-09 04:05 EST by b.g.m.kusters
Modified: 2008-05-01 11:37 EDT (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2000-11-10 04:42:20 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description b.g.m.kusters 2000-11-09 04:05:52 EST
Tested in bash and bash2

Parameter assignment in loop is not exported out of the loop if read is used see script.
Same error occures if read is used in combinatie with pipe eg. 
tail -n 1 x2 | read p1 p2.
No assignment to parameters read take place.


#!/bin/bash2
echo "1" > x2
echo "2" >> x2
echo "Error parameter not exported"
d=""
cat x2|while read p1
do
 echo "d1 = $d"
 d="${d}${p1}"
 echo "d2 = $d"
done
echo "d3 = $d"

echo ""
echo "No Error parameter is exported"
d=""
set $(cat x2)
while [ $# -ne 0 ]
do
 p1=$1
 shift 1
 echo "d1 = $d"
 d="${d}${p1}"
 echo "d2 = $d"
done
echo "d3 = $d"
Comment 1 b.g.m.kusters 2000-11-09 04:10:42 EST
TESTED with RedHat 6.2 not 4.2
Comment 2 Bernhard Rosenkraenzer 2000-11-10 04:46:27 EST
This is another effect of the modifications to make bash compliant to the Single UNIX Specification (See bug #19747).


*** This bug has been marked as a duplicate of 19747 ***

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