[Top][All Lists]

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

Re: Space removal in AE takes place before brace expansion

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

On 4/30/17 2:31 PM, Florian Mayer wrote:
> I want to add up all numbers from 1 to 10, but when I do 
> $ echo $(({1,10}’+’ +0)) # with a space between the first + and the second one
> I get an error:
> bash: ((: 1+ ,3 10+ ,3: syntax error: operand expected (error token is ",3 
> 10+ ,3“)

First of all, this is too clever by half. There are many clearer ways to
add the numbers from 1 to 10.  Second, you are using a comma where you
probably mean `..'.

Once you take out the weird UTF-8 quotes, brace expansion isn't performed
at all. It never has been performed on something that looks like it could
be a command substitution (it defers to the subshell that's started to run
the command substitution). A future version of bash will probably assume
that $(( begins an arithmetic substitution and perform the expansion, but
no version of bash does that today.

Even if you were using a modified version of bash that did this, there is
no way you would get `,3' out of it, since it doesn't appear anywhere in
the original statement.

> It seems as if brace expansion gets executed first (as expected) but with
> all the spaces removed that had existed before inside the (( )) parentheses 
> pair.
> The line
> $ (( {1, 10}'+' ,3)) # (space between 1 and 10)
> also gives the same error and thus shows that spaces are removed before
> brace expansion takes place. Why is that?

This does perform brace expansion, but it expands to two words

        " 1+ ,3" and "  10+ ,3"

which eventually get passed to the expression evaluator as
" 1+ ,3  10+ ,3"

It's very hard to figure out what you might be expecting here.

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

reply via email to

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