Re: array subscripts act differently for integers(ie. let)

2015-02-21 Thread Chet Ramey
On 2/20/15 3:52 PM, Dan Douglas wrote:

> IMO bash is exactly correct. I don't know how this could be "fixed" in
> a way that would satisfy people without changing something very
> fundamental. If you disable the initial expansion to `(())', then
> `(($x))' wouldn't work (because arithmetic evaluation doesn't itself
> evaluate parameter expansions). However if you disabled evaluating
> parameter expansions during variable resolution (for array indexes)
> then you would be stuck with exactly the above ksh problem.

Yeah, exactly.  I could potentially avoid the double-expansion issue
by adding flags and other conditional beahvior, but I'm afraid it
would be fragile and inconsistent.  The backwards compatibility issue
would come up either way.

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



Re: declare in a function makes a variable unable to be found with declare -p in some cases

2015-02-21 Thread Chet Ramey
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, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/