Bug 141147

Summary: while statement hides values assigned
Product: Red Hat Enterprise Linux 3 Reporter: John P. bland <jpbland>
Component: bashAssignee: Tim Waugh <twaugh>
Status: CLOSED NOTABUG QA Contact: Ben Levenson <benl>
Severity: medium Docs Contact:
Priority: medium    
Version: 3.0   
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2004-11-29 17:16:21 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Description John P. bland 2004-11-29 16:54:59 UTC
Description of problem: when executing a while statement and assigning
a value to a variable, the value does not exist after the while loop
is completed:

The following is the script

cd /usr/share/terminfo/w
x2=""                                
export x2                            
 ls wy50*|while read x1                
 do                                  
   if [ "X"$x2 = "X" ]               
     then :                          
   else                              
     x2=$x2","                       
   fi                                
   x2=$x2$x1                         
 done                                
echo $x2                             



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

2.05b.0

How reproducible:

See above command segment

Steps to Reproduce:
1.
2.
3.
  
Actual results:

x2=""

Expected results:

wy50,wy50-mc,wy50-vb,wy50-w,wy50-wvb   

Additional info:

for x1 in `ls wy50*`  

instead of 

ls wy50*|while read x1   

does work

Comment 1 John P. bland 2004-11-29 16:57:13 UTC
in expected results the variable x2 should be set to the listed data

Comment 2 Tim Waugh 2004-11-29 17:16:21 UTC
Please see the bash FAQ, question E4: /usr/share/doc/bash-*/FAQ.