Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #11934 > unrolled thread
| Started by | Greg Wooledge <wooledg@eeg.ccf.org> |
|---|---|
| First post | 2015-11-30 08:29 -0500 |
| Last post | 2015-11-30 08:29 -0500 |
| Articles | 1 — 1 participant |
Back to article view | Back to gnu.bash.bug
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: An array variable created by export/readonly builtins inside a function becomes a locale variable to that function unexpectedly Greg Wooledge <wooledg@eeg.ccf.org> - 2015-11-30 08:29 -0500
| From | Greg Wooledge <wooledg@eeg.ccf.org> |
|---|---|
| Date | 2015-11-30 08:29 -0500 |
| Subject | Re: An array variable created by export/readonly builtins inside a function becomes a locale variable to that function unexpectedly |
| Message-ID | <mailman.1007.1448890189.31583.bug-bash@gnu.org> |
On Sat, Nov 28, 2015 at 11:18:24AM +0800, ziyunfei wrote:
> $ bash -c 'foo() { readonly a=(1);echo a=$a; }; foo; echo a=$a' # a becomes a local variable
> a=1
> a=
"readonly" is a synonym for "declare -r", and declare (without the -g
option) always marks variables as local when used in a function.
If you want variables created in a function NOT to be local to that
function, you must skip all declarations entirely. Just create the
variable by assigning to it.
Back to top | Article view | gnu.bash.bug
csiph-web