[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
"declare" builtin creates local variables within functions
From: |
hcz |
Subject: |
"declare" builtin creates local variables within functions |
Date: |
Tue, 05 Apr 2005 22:28:25 +0200 |
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-pc-linux-gnu'
-DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL
-DHAVE_CONFIG_H -I. -I../bash -I../bash/include -I../bash/lib -g -O2
uname output: Linux tazzelwurm 2.6.11hcz1 #2 Fri Mar 11 20:01:21 CET 2005 i686
GNU/Linux
Machine Type: i386-pc-linux-gnu
Bash Version: 3.0
Patch Level: 16
Release Status: release
Description:
When variables are created with the "declare" builtin while in
a function, they go out of scope when the function is left.
Repeat-By:
#!/bin/bash
foo(){
declare bar="y"
echo local:
declare -p bar
}
declare baz=12
foo
echo global:
declare -p bar baz
This outputs:
local:
declare -- bar="y"
global:
./x.sh: line 12: declare: bar: not found
declare -- baz="12"
Note: "bar" in the example above is not really handled like a generic
local variable. If the variable is already known at global level, the
"declare" within the function assigns to the global. So doing a
"bar=" before the "declare" is executed (even within the function)
makes the error disapper.
Thanks for your good job,
Heike
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- "declare" builtin creates local variables within functions,
hcz <=