bug-bash
[Top][All Lists]
Advanced

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

Bug in bash?


From: address@hidden
Subject: Bug in bash?
Date: Tue, 14 Dec 2004 10:47:56 -0700

From: address@hidden
To: address@hidden,address@hidden
Subject: function | grep foo makes global variables as local variables
Message-Id: <address@hidden>
Date: Tue, 14 Dec 2004 10:42:42 -0700

Configuration Information [Automatically generated, do not change]:
(This bug exists in other versions and other platforms also)
Machine: ia64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='ia64'
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='ia64-unknown-linux-gnu'
-DCONF_VENDOR='unknown' -DSHELL -DHAVE_CONFIG_H  -I.  -I../bash
-I../bash/include -I../bash/lib  -g -O2
uname output: Linux nemesis1 2.6.7-telco-1.0-mckinley-smp #1 SMP Fri Aug
6 16:59:57 MDT 2004 ia64 GNU/Linux
Machine Type: ia64-unknown-linux-gnu

Bash Version: 2.05b
Patch Level: 0
Release Status: release

Description:
When the function output is piped to a command inside a script, all the
global variables used inside the function are treated as local
variables.

Repeat-By:
Create a script first.sh, include the following and execute it
#-----------------------------------------------------------
#!/bin/bash

GLOBAL1=0

change_it()
{
        GLOBAL1=2
        echo "GLOBAL1 now is $GLOBAL1"
}

echo "GLOBAL1 now is $GLOBAL1"
change_it
echo "GLOBAL1 now is $GLOBAL1"
----------------------------------------------------------------
Create a second script first_bug.sh, include the following and execute
it
----------------------------------------------------------------------
#!/bin/bash
# The difference is grep executes in a new process

GLOBAL1=0

change_it()
{
        GLOBAL1=2
        echo "GLOBAL1 now is $GLOBAL1"
}

echo "GLOBAL1 now is $GLOBAL1"
change_it | grep now
echo "GLOBAL1 now is $GLOBAL1"
----------------------------------------------------------------------
I was expecting the second script to treat the GLOBAL1 variable as
global variable instead of a local variable in the second case also.






reply via email to

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