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: Chet Ramey
Subject: Re: declare in a function makes a variable unable to be found with declare -p in some cases
Date: Sat, 21 Feb 2015 12:15:46 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:31.0) Gecko/20100101 Thunderbird/31.2.0

On 2/20/15 2:42 PM, SN wrote:

> Thanks to you both for the answers. I am glad to see that my original
> issue has been fixed.
> The thread is indeed long and detailed, so let me just leave a note
> about a weird behaviour with 4.4.0 (devel) I have that may or may not be
> the intended behaviour.
> 
> bash-4.4$ e='(`uname >&2`)'; declare -a a=$e; echo "[$a]"
> Linux
> []
> bash-4.4$ e='(`uname >&2`)'; declare -a a=$e; echo "[$a]"
> [(`uname >&2`)]
> 
> As you can see, only in the second case uname is not run. (One can also
> type "unset a" to have it execute again.) So there seems to be another
> inconsistency.

It's intentional.  Read

http://lists.gnu.org/archive/html/bug-bash/2014-12/msg00115.html

for some context, especially this part:

        So, the main difference with the current behaviour would be that

        declare a='(1 2 3)'

        or:

        declare 'a=(1 2 3)'

        or

        declare a='([0]=a [1]=b)'

        would not be an array (or hash) assignment if a was previously
        declared as a hash or array.

        declare -a a='(1 2)'

        would still be but be deprecated in favour of:

        declare -a a=(1 2)
        or
        declare a=(1 2)

I have played around a little with this section of code, and it will
probably change some more before bash-4.4 is released.

> By the way, I use `cmd` instead of $() because I have this:
> $  : $(echo x)
> bash: command substitution: line 8: syntax error near unexpected token `)'
> bash: command substitution: line 8: `echo x)'

You probably built bash using byacc, which has major problems with
recursive calls to yyparse().  `configure' should have displayed a
warning when you ran it.

Chet
-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    chet@case.edu    http://cnswww.cns.cwru.edu/~chet/



reply via email to

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