bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

iGlobal variable not updated in while loop when reading from pipe


From: jwiegand
Subject: iGlobal variable not updated in while loop when reading from pipe
Date: Mon, 1 Dec 2003 17:21:48 GMT

Configuration Information [Automatically generated, do not change]:
Machine: i386
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='i386' 
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i386-redhat-linux-gnu' 
-DCONF_VENDOR='redhat' -DSHELL -DHAVE_CONFIG_H  -D_GNU_SOURCE 
-D_FILE_OFFSET_BITS=64  -I.  -I. -I./include -I./lib -I/usr/include -O2 
-march=i386 -mcpu=i686
uname output: Linux admin.bgremote.com 2.4.2-2smp #1 SMP Sun Apr 8 20:21:34 EDT 
2001 i686 unknown
Machine Type: i386-redhat-linux-gnu

Bash Version: 2.04
Patch Level: 21
Release Status: release

Description:
        The variables free, use, and siz are supposed to accumulate the 
variables read in from the pipeline.  However, once the while loop is done, 
their value outside of the loop is still 0.  The script works as expected in
the Korn shell.

Repeat-By:
Run the following script:

#!/bin/bash -x
free=0
use=0
siz=0
echo -e "1 2 3\n1 2 3" |
while read s u f 
do
   echo "Line in: $s $u $f"
   free=$(( $f + $free ))
   use=$(( $u + $use ))
   siz=$(( $s + $siz ))

   echo "Total Size        Used Space           Available"
   echo "----------        ----------           ---------"
   echo "$siz                 $use                    $free"
done

echo "Total Size        Used Space           Available"
echo "----------        ----------           ---------"
echo "$siz                 $use                    $free"

free=$(( 0 + $free ))
use=$(( 0 + $use ))
siz=$(( 0 + $siz ))




reply via email to

[Prev in Thread] Current Thread [Next in Thread]