[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Space removal in AE takes place before brace expansion
From: |
Florian Mayer |
Subject: |
Re: Space removal in AE takes place before brace expansion |
Date: |
Mon, 01 May 2017 15:29:43 +0200 |
> sum=0; for ((i=1; i<=10; i++)); do ((sum+=i)); done
You can actually omit ‚sum=0;‘, because bash dereferences unset variables to 0
(according to the holy manual of course).
> I cannot figure out what you actually typed here, because your UTF-8
I don’t know what caused that, but it was not intentionally.
https://lists.gnu.org/archive/html/bug-bash/2017-04/msg00152.html
correctly shows what I’ve submitted.
> You should NOT be entering UTF-8 characters into bash commands, unless
I know. I did not.
> I really, very strongly, discourage you from pursuing this line of
I’d rather like you to save your recommendations regarding how I am supposed to
do things.
> Am 01.05.2017 um 15:10 schrieb Greg Wooledge <wooledg@eeg.ccf.org>:
>
> 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.