[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Undocumented local scope for variable (even exported!)
From: |
Pavel Tolkachev |
Subject: |
Undocumented local scope for variable (even exported!) |
Date: |
Mon, 31 Mar 2003 09:51:29 -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 dwebr1 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:
In some reasonably common code, bash seems to put the variables in
undocumented local scope. Here is the code:
-----cut here-(script 2)---
a=1
export a
echo "a=$a"
echo "bc" | while read b; do
a=2
export a
echo "a=$a"
done
echo "a=$a"
-----cut here--(script 2)--
and here is the output
-----cut here-(result 1)---
a=1
a=2
a=1
-----cut here-(result 1)---
At the same time, if we do not use a pipe to the while, for example:
-----cut here--(script 2)--
a=1
export a
echo "a=$a"
while true; do
a=2
export a
echo "a=$a"
break
done
echo "a=$a"
-----cut here--(script 2)--
The output is as expected:
-----cut here--(result 2)--
a=1
a=2
a=2
-----cut here--(result 2)--
In fact, it seems to me that the Korn-shell on my Linux box is actually
implemented somehow using bash code because it gives the same result. There is
no link, and the file size is different but it gives the same result for the
script 1. The same script 1 run by the Korn-shell on Solaris or AIX gives the
expected result (result 2). But bash gives the result 1 consistently on all
those platforms (Linux AIX and Solaris) for script 1 (and result 2 for script
2).
Repeat-By:
See the code above -- no special circumstances are required
Have a nice day,
Pavel
--
This e-mail may contain confidential and/or privileged information. If you are
not the intended recipient (or have received this e-mail in error) please
notify the sender immediately and destroy this e-mail. Any unauthorized
copying, disclosure or distribution of the material in this e-mail is strictly
forbidden.
- Undocumented local scope for variable (even exported!),
Pavel Tolkachev <=