bug-bash
[Top][All Lists]
Advanced

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

Cannot set variable declared outside of nested while loop


From: Rick Wargo
Subject: Cannot set variable declared outside of nested while loop
Date: Mon, 16 Jan 2006 23:28:54 -0500

Configuration Information [Automatically generated, do not change]:

Machine: i386

OS: linux-gnu

Compiler: i386-redhat-linux-gcc

Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='i386'
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i386-redhat-linux-gnu'
-DCONF_VENDOR='redhat' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash'
-DSHELL -DHAVE_CONFIG_H  -I.  -I. -I./include -I./lib  -D_GNU_SOURCE
-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -O2 -g -pipe
-Wp,-D_FORTIFY_SOURCE=2 -fexceptions -m32 -march=i386 -mtune=pentium4
-fasynchronous-unwind-tables

uname output: Linux chocolate.shorebell.local 2.6.14-1.1656_FC4 #1 Thu
Jan 5 22:13:22 EST 2006 i686 i686 i386 GNU/Linux

Machine Type: i386-redhat-linux-gnu

 

Bash Version: 3.0

Patch Level: 16

Release Status: release

 

Description:

       Cannot set variable declared outside of nested while loop within
a function. This works in ksh. :(

       See example below for a better explanation.

 

Repeat-By:

 

func1()

{

  if [ -n "$a" ]

  then

        a="$1|$a"

  else

        a="$1"

  fi

}

 

bad()

{

  (echo abc;echo def;echo ghi) |

  while read line

  do

        echo $line |

        while read lh

        do

           func1 "$lh"

        done

  done

}

 

good()

{

  (echo abc;echo def;echo ghi) |

  while read line

  do

        func1 "$line"

  done

}

 

a=""

bad           ## this has a problem accessing a

echo $a       ## this echoes nothing

 

a=""

good          ## this sets a properly but is not accessible in next line

echo $a       ## this echoes nothing



reply via email to

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