[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Arithmetic expressions and parameters with newlines breaks
From: |
Bob Proulx |
Subject: |
Re: Arithmetic expressions and parameters with newlines breaks |
Date: |
Mon, 2 Jul 2007 14:25:12 -0600 |
User-agent: |
Mutt/1.5.9i |
Jan Schampera wrote:
> Well, I guess intuitively expected that it evaluates to 0, like for
> example:
>
> $ test=string
> $ echo $((test))
> 0
In that case it is like the 'atoi(3)' routine. A non-numeric has no
number value and is evaluated to be zero. A single zero is a valid
arithmetic expression.
$ echo $((0))
0
But two numbers is a different case.
$ echo $((0 0))
sh: line 1: 0 0: syntax error in expression (error token is "0")
This is the same in bash as in other languages too. They are all very
similar on this point.
> But I just made some experiments (which I should have done before) and
> read the manual again a bit closer: In this example I really reference
> the variable "string" (as designated operand) which is unset/null and
> thus evaluates to 0.
>
> I also saw this can be done in any depth.
Yes. Well, all's well that ends well. :-)
> So, excuse my wrong interpretion of the manual (maybe that needs to be
> marked extra by a sentence or a half in manual). It's definitely not a
> bug (it is - between screen and chair!).
Suggestions for improvements to the documentation are always
appreciated.
> Best regards and thanks again for quick reply,
Good luck!
Bob