[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
declare -x in function, is like local keyword, not like export keyword
From: |
Siim Kaalep |
Subject: |
declare -x in function, is like local keyword, not like export keyword |
Date: |
Thu, 05 Feb 2004 16:41:37 +0200 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4.1) Gecko/20031114 |
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' -DSHELL -DHAVE_CONFIG_H -I. -I. -I./include
-I./lib -D_FILE_OFFSET_BITS=64 -O2 -g -pipe -march=i386 -mcpu=i686
uname output: Linux ziim 2.4.22-1.2149.nptlcustom #1 Thu Jan 15 21:45:22
EET 2004 i686 athlon i386 GNU/Linux
Machine Type: i386-redhat-linux-gnu
Bash Version: 2.05b
Patch Level: 0
Release Status: release
Description:
man declare(BASH_BUILTINS(1)) states following(copied only concerning
parts):
declare [-afFirtx] [-p] [name[=value]]
-x Mark names for export to subsequent commands via the environment.
Using ‘+’ instead of ‘-’ turns off the attribute instead, ... some +a
exception.
When used in a function, makes each name local, as with the local command.
Problem: When declare -x is used in function, it does act like local
keyword. But consulting manual someone would expect export keyword like
behaviour. Or if -x is not supposed to work inside function, it maybe
better to generate error.
Repeat-By:
Scripts:
$ cat test_bare.sh
#!/bin/bash
testFunc () {
TEST=1
}
testFunc
echo $TEST
./echo_TEST.sh
$ cat test_declare-x.sh
#!/bin/bash
testFunc () {
declare -x TEST=1
}
testFunc
echo $TEST
./echo_TEST.sh
$ cat test_declare+x.sh
#!/bin/bash
testFunc () {
declare +x TEST=1
}
testFunc
echo $TEST
./echo_TEST.sh
$ cat test_export.sh
#!/bin/bash
testFunc () {
export TEST=1
}
testFunc
echo $TEST
./echo_TEST.sh
$ cat test_local.sh
#!/bin/bash
testFunc () {
local TEST=1
}
testFunc
echo $TEST
./echo_TEST.sh
$ cat echo_TEST.sh
#!/bin/bash
echo $TEST
$
Output:
$ ./test_bare.sh
1
$ ./test_declare-x.sh
$ ./test_declare+x.sh
$ ./test_export.sh
1
1
$ ./test_local.sh
$
Fix:
solution 1)make declare -x equivalent to export. That is imho intuitive
behaviour as declare -r is equivalent to readonly keyword.
if solution 1 is impossible for some historical reason:
solution 2)State in manual that option "x" is ignored in function. And
if declare -x is found in function, it would be nice to generate error.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- declare -x in function, is like local keyword, not like export keyword,
Siim Kaalep <=