bug-bash
[Top][All Lists]
Advanced

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

Re: brace expansion fails in 4.3, succeed in 4.2


From: Dan Douglas
Subject: Re: brace expansion fails in 4.3, succeed in 4.2
Date: Sat, 10 May 2014 23:06:01 -0700 (PDT)
User-agent: KMail/4.13 (Linux/3.14.0-pf3+; KDE/4.13.0; x86_64; ; )

On Saturday, May 10, 2014 11:28:44 PM NBaH wrote:
> Do you mind explaining a little bit «the way Bash parses array
> subscripts» ?
>

Didn't notice this reply (as I failed to mention, this is slightly
ridiculous code. Use a loop for important code of course).

It skips over any text between the closing bracket and parameter
expansion operator (if any). That combined with referencing the zeroth
element of an array being a synonym for the variable itself even if it
doesn't have an array attribute.

So that expands to: "${a[0]0}" "${a[0]1}" etc. Bash ignores the number
after `]` and treats ${a[0]} as "$a". Meanwhile the math side-effect
before the comma operator modifies a[0] as it goes.

I've done worse. Here's a million args via plain brace expansion (not
sequence expansion). Also possibly the only ever "practical" usage of
GNU factor(1) (or at least the silliest).

http://wiki.bash-hackers.org/syntax/expansion/brace#more_fun

--
Dan Douglas



reply via email to

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