effect of assignment to a shell variable inside while list is lost outsi
From:
John Lumby
Subject:
effect of assignment to a shell variable inside while list is lost outside list
Date:
Thu, 23 Jan 2003 23:15:26 -0500
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 lumbyrnt 2.4.7-10 #1 Thu Sep 6 17:27:27 EDT 2001 i686
unknown
Machine Type: i386-redhat-linux-gnu
Bash Version: 2.05
Patch Level: 8
Release Status: release
Description:
when I run this:
typeset -i rc=1;line="";echo -e "line 1\\nline 2" | while read -r
line; do { [[ "$line" == *1 ]] && rc=0 && echo "rc=$rc line=$line" &&
break; };done;echo "rc=$rc line=$line"
I see this:
rc=0 line=line 1
rc=1 line=
I don't understand why the values of rc and line most recently set
(inside the while list) are lost and original values (from init prior to
loop) are
reinstated. This is contrary to my understanding of scope of shell
variables.
Repeat-By:
See above
Fix:
_________________________________________________________________