[Toybox] Would someone please explain what bash is doing here?

enh enh at google.com
Tue Mar 10 09:50:27 PDT 2020


On Tue, Mar 10, 2020 at 8:42 AM Chet Ramey <chet.ramey at case.edu> wrote:
>
> On 3/9/20 11:16 PM, Rob Landley wrote:
>
> > Oh I imagine just about everything sees use.
> >
> >   $ echo $((2**3))
> >   8
> >   $ 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
> >   1
>
> 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
>         done
>
> 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
> again.
>
>
> >> -- 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.

except like you said, bash (like MS Word) has that property where most
people only use a few percent of the functionality, but everyone's
using a different few percent. the only bugs i see reported against
mksh (which is what Android's used for the last ~decade) are basically
"i just want this one thing from bash". i'm not super excited about
suffering another shell transition, especially because we have another
10 years worth of accumulated scripts since the last time, but a shell
that explicitly aims to be bash-compatible (unlike mksh, which
doesn't) is the only thing that would make it even worth thinking
about.

i've even contemplated having a /bin/bash symlink to mksh just to make
scripts that assume #!/bin/bash is there just work -- because one
consequence of dash is that a lot of scripts that would work fine with
most shells now explicitly call for bash regardless -- but my
conscience prevents me from doing so as long as we're on a shell that
doesn't consider differences from bash to be a bug!

> Chet
>
> --
> ``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 mailing list