bug-bash
[Top][All Lists]
Advanced

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

Re: Clarification - Space removal in AE takes place before brace expansi


From: Chet Ramey
Subject: Re: Clarification - Space removal in AE takes place before brace expansion
Date: Mon, 1 May 2017 10:26:55 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Thunderbird/52.0.1

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    chet@case.edu    http://cnswww.cns.cwru.edu/~chet/



reply via email to

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