[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Space removal in AE takes place before brace expansion
From: |
Greg Wooledge |
Subject: |
Re: Space removal in AE takes place before brace expansion |
Date: |
Mon, 1 May 2017 09:10:31 -0400 |
User-agent: |
Mutt/1.4.2.3i |
On Sun, Apr 30, 2017 at 08:31:30PM +0200, Florian Mayer wrote:
> I want to add up all numbers from 1 to 10,
sum=0; for ((i=1; i<=10; i++)); do ((sum+=i)); done
> but when I do
> $ echo $(({1,10}???+??? +0)) # with a space between the first + and the
> second one
I cannot figure out what you actually typed here, because your UTF-8
characters have been replaced by three question marks in my mail client.
What I see is literally: echo $(({1,10}???+??? +0))
You should NOT be entering UTF-8 characters into bash commands, unless
they're literal characters that are part of a string that you want to
store or print or pass as an argument. They should certainly not be
part of an arithmetic expression.
> I get an error:
> bash: ((: 1+ ,3 10+ ,3: syntax error: operand expected (error token is ",3
> 10+ ,3???)
So you are trying to be CLEVER? You are trying to trick bash into
executing code that generates code that will then be evaluated? And you
didn't even explictly call eval?
I really, very strongly, discourage you from pursuing this line of
solutions. Generating code with the intent to eval it is NOT the way
to go for a simple arithmetic problem. Just use a loop.
- Re: Space removal in AE takes place before brace expansion,
Greg Wooledge <=