bug-bash
[Top][All Lists]
Advanced

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

Re: declare in a function makes a variable unable to be found with decla


From: Eduardo A . Bustamante López
Subject: Re: declare in a function makes a variable unable to be found with declare -p in some cases
Date: Tue, 17 Feb 2015 16:46:38 -0600
User-agent: Mutt/1.5.21 (2010-09-15)

I'm pretty sure this was already discussed in this thread:
* http://lists.gnu.org/archive/html/bug-bash/2014-12/msg00108.html

But... it's huge, so it's hard to find the precise part where this
was discussed.

Also, remember to state the version you're using. This particular
feature seems to behave differently in the -devel branch:


| $ cat declare.bash
| #!/bin/bash
| 
| for bash in /tmp/bash-* /bin/bash; do
|   "$bash" --version
|   printf '%s\n' ---
|   "$bash" -c 'declare -a a; declare -p a'
|   "$bash" -c 'declare -a a=(); declare -p a'
|   "$bash" -c 'declare -a a="()"; declare -p a'
|   "$bash" -c 'f(){ declare -a a; declare -p a; }; f'
|   "$bash" -c 'f(){ declare -a a=(); declare -p a; }; f'
|   "$bash" -c 'f(){ declare -a a="()"; declare -p a; }; f'
|   printf '%s\n' ---
| done
| 
| $ ./declare.bash
| GNU bash, version 4.4.0(1)-devel (x86_64-unknown-linux-gnu)
| Copyright (C) 2014 Free Software Foundation, Inc.
| License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
| 
| This is free software; you are free to change and redistribute it.
| There is NO WARRANTY, to the extent permitted by law.
| ---
| declare -a a
| declare -a a=()
| declare -a a=()
| declare -a a
| declare -a a=()
| declare -a a=([0]="()")
| ---
| GNU bash, version 4.3.33(1)-release (x86_64-unknown-linux-gnu)
| Copyright (C) 2013 Free Software Foundation, Inc.
| License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
| 
| This is free software; you are free to change and redistribute it.
| There is NO WARRANTY, to the extent permitted by law.
| ---
| /tmp/bash-master: line 0: declare: a: not found
| declare -a a='()'
| declare -a a='()'
| /tmp/bash-master: line 0: declare: a: not found
| declare -a a='()'
| /tmp/bash-master: line 0: declare: a: not found
| ---
| GNU bash, version 4.2.37(1)-release (x86_64-pc-linux-gnu)
| Copyright (C) 2011 Free Software Foundation, Inc.
| License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
| 
| This is free software; you are free to change and redistribute it.
| There is NO WARRANTY, to the extent permitted by law.
| ---
| declare -a a='()'
| declare -a a='()'
| declare -a a='()'
| declare -a a='()'
| declare -a a='()'
| declare -a a='()'
| ---

You're reporting the behavior of the master branch, but it seems to
be already fixed in devel. I'm not sure about the inconsistency
between:
|   "$bash" -c 'declare -a a="()"; declare -p a'
and
|   "$bash" -c 'f(){ declare -a a="()"; declare -p a; }; f'

IMO these two should have the same behaviour. Chet will be able to
clarify this.



reply via email to

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