[Toybox] Would someone please explain what bash is doing here?
chet.ramey at case.edu
Tue Mar 10 08:42:56 PDT 2020
On 3/9/20 11:16 PM, Rob Landley wrote:
> Oh I imagine just about everything sees use.
> $ echo $((2**3))
> $ echo $((2**3.4))
> bash: 2**3.4: syntax error: invalid arithmetic operator (error token is ".4")
Yeah, bash doesn't do any floating point at all. Use awk or bc.
> I have not yet opened the $(( )) and for ((;;)) cans of worms yet. I eventually
> figured out that (( )) on the command line is because you can assign values to
> variables, so you can do:
> $ ((x++)); echo $x
Not so much. It's more so you can do C-like things like
while ((i > 0)) ; do
something that may or may not include i
without using test. It's basically $(( )) with a return value you can use
(or, more precisely, $(( )) is (( )) converted to a word expansion).
The arithmetic for loop is just syntactic sugar. I don't know if I'd do it
>> -- but i can't even imagine a world in
>> which someone comes to me asking for more *dash* compatibility :-)
> It was a mistake Ubuntu made and pushed "upstream" into debian. The goal was
> never "remove everything that's not in posix", that was just a side effect.
Minimalism and POSIX conformance are the big selling points now, at least
on the shell side of things.
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU chet at case.edu http://tiswww.cwru.edu/~chet/
More information about the Toybox