Mailinglist Archive: opensuse-factory (602 mails)

< Previous Next >
Re: [opensuse-factory] Can we assume that /bin/sh is bash?
  • From: Joerg Schilling <Joerg.Schilling@xxxxxxxxxxxxxxxxxxx>
  • Date: Mon, 11 Feb 2019 12:11:18 +0100
  • Message-id: <5c615856.R/>
Jan Engelhardt <jengelh@xxxxxxx> wrote:

Btw the comparison is a bit unfair: "configure", by design, is written
in the most portable shell dialect possible, forfeiting all chances for
bash to catch up with optimized builtins.

So, have bash invest a bit in optimizing the base dialect.
It seems ridiculous that a mere syntactical difference leads to
such great discrepancies:

» for ((i=0; i<1000000;++i)); do echo '[ "$a$b" = 5 ]'; done >ca1
» for ((i=0; i<1000000;++i)); do echo '[[ "$a$b" = 5 ]]'; done >ca2
» time pbosh ca1
real 0m3.198s user 0m3.145s sys 0m0.052s
» time bash ca1
real 0m3.987s user 0m3.985s sys 0m0.000s
» time bash ca2
real 0m2.669s user 0m2.668s sys 0m0.000s

If anything else, this reeks of embrace-extend-extinguish. First make
[ suck, add [[, then make everyone write [[ just to be able to reach
or beat the [ implementation of another sh. Something is wrong here.

Interesting catch!

BTW: ksh93 has less differences between [ and [[.

Also note that this is a ksh88 feature that has been introduced in order to
avoid problems when the position of an operator may be a shell macro and this
has been introduced before POSIX rearranged the test(1) definition to mainly
depend on the number of parameters.

PPS: the next version of bosh will be approx. 15% faster with this command and
should be approx. as fast as bash with [[ now. I just make a minor change to the
memory management module.


EMail:joerg@xxxxxxxxxx (home) Jörg Schilling D-13353 Berlin
joerg.schilling@xxxxxxxxxxxxxxxxxxx (work) Blog:
To unsubscribe, e-mail: opensuse-factory+unsubscribe@xxxxxxxxxxxx
To contact the owner, e-mail: opensuse-factory+owner@xxxxxxxxxxxx

< Previous Next >