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