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