bug-bash
[Top][All Lists]
Advanced

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

unset does not work as expected in functions.


From: MAL
Subject: unset does not work as expected in functions.
Date: Tue, 20 Jan 2004 15:46:29 +0000
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.5) Gecko/20031118

Configuration Information [Automatically generated, do not change]:
Machine: i686
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='i686' -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i686-pc-linux-gnu' -DCONF_VENDOR='pc' -DSHELL -DHAVE_CONFIG_H -I. -I. -I./include -I./lib -march=athlon -O2 -pipe uname output: Linux komcept-mal.komcept.gotdns.com 2.6.1-rc1 #1 Tue Jan 6 12:11:51 GMT 2004 i686 AMD Athlon(tm) processor AuthenticAMD GNU/Linux
Machine Type: i686-pc-linux-gnu

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

Description:

When you unset a variable declared as an integer (declare -i), inside a function, then try to reuse it as a text variable, it continues to act like and integer (assigning a string to it results in 0 being stored).

Repeat-By:

The program:

***START***
#!/bin/bash
declare -i i=3
echo $i
unset i
echo $i
i="test"
echo $i
****END****

works as expected, producing:

***START***
3

test
****END****

But put the code inside a function:

***START***
#!/bin/bash
test() {
declare -i i=3
echo $i
unset i
echo $i
i="test"
echo $i
}

test
****END****

and you get:

***START***
3

0
****END****

The unset variable is still being treated as an integer.



MAL





reply via email to

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