[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

ash vs. bash



Hi,
i am a newcomer to this list, but I have been a debian users for a few
years. I apologize if this topic has been discussed before. I have
always wondered why debian (and I'm sure most other distributions)
come with /bin/sh that is actually a link to bash. The latter is an
excellent choice for interactive use, but I do a lot of programming
with the shell, and Kennet Almiquist's /bin/ash (available as optional)
is a much more Bourne-like implementation, much faster than bash for
shell scripts and a much smaller executable too. Many other non-linux
boxes, SunOS for instance, but also AIX, come with a /bin/sh which is
only a few tens of Kbytes in size, and is an actual, fast, bare-bone
Bourne shell. Apart from the size of the executable and the associated
faster startup/initialization time, here is a speed-wise comparison
between the two on a PII 233 Debian 2.1 box:

cat test-script

for i in `seq 1 999`
do
  echo $i
done


time sh ./test-script >/dev/null

real    0m0.240s
user    0m0.240s
sys     0m0.000s


time ash ./test-script >/dev/null

real    0m0.066s
user    0m0.040s
sys     0m0.020s


The difference in execution speed is self-evident. Actually bash can be
compiled in a minimal, stripped-down version, but even then it is still
200 KB in size, and speed-wise it does not improve much. Linking
/bin/sh to /bin/ash as opposed to /bin/bash would propagate the
performance advantage to those programs that use the system(3) library
call, and those that use /bin/sh extensively to interact with the
undelying OS (/usr/bin/awk is one of those: opening pipes or running
system() instructions fork /bin/sh). Programs that expect system(3) to
use a real bourne shell may fail if /bin/sh links to bash. Netscape is
one of those, as it starts external players with "sh -c ((player %s); rm %s)"
and the '((' chunk triggers bash's arithmetical expansion code, instead.

I am pretty sure this must have be touched upon before and I would 
really like to know what where the conclusions.

Many thanks

-- 
Carlo Strozzi       PGP Public Key fingerprint :
ED 4A 7A 6C 88 66 1B 34  06 14 FC 2E C7 EA F2 EE

Against software patents: http://no-patents.prosa.it


Reply to: