On 5/1/17 9:49 AM, Florian Mayer wrote:

> However,
> $ (({1..10}'+' +0))
> Gives me "bash: ((: 1+ +0 2+ +0 3+ +0 4+ +0 5+ +0 6+ +0 7+ +0 8+ +0 9+ +0
> 10+ +0: syntax"
> which is the same thing I'd get, when I whould've done {1..10}'+ +0'. Thus
> in this same arithmetic expansion context bash _does_ indeed do brace
> expansion. But it does
> it after it deleted all whitespace inside the (( )) pair.

OK.  This starts out as one word: "{1..10}'+' +0". Brace expansion
considers it as a null preamble, a brace expansion consisting of {1..10}
and a postscript consisting of "'+' +0".  The brace expansion portion gets
processed, resulting in 10 words: "1", "2", "3", and so on. The rest of
the original word gets appended to each generated word, resulting in

1'+' +0
2'+' +0
3'+' +0
  ...

Each of those words undergoes the usual set of word expansions, resulting
in

1+ +0
2+ +0
3+ +0
  ...

Those words get turned into a single string for the expression evaluator,
in the same way that "$@" gets turned into a single word in places where
word splitting doesn't occur, which results in an expression of

"1+ +0 2+ +0 3+ +0 4+ +0 5+ +0 6+ +0 7+ +0 8+ +0 9+ +0 10+ +0"

That's obviously a syntax error. The whitespace that exists in the original
word (the space between the `+ +') is preserved.

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

Reply via email to