Finn Thain dixit:

>For some time I have been meaning to check out mksh, and your email 
>prompted me to install it. The first thing I noticed was how good the 
>documentation is (the bash man page is missing a lot of stuff).

Great! Most of the manual page was not written by me, mind you,
standing on the shoulders of giants and all that, but still
appreciated.

>I played around with mksh for a while and noticed some other differences 
>with bash. Parameter assignment using here-docs is a nice feature. Another 
>difference is double logical complement. The mksh result was the one I was 
>expecting --

Ouch @bash. Well yes, it does have some odd corners, but this
one is definitely unexpected.

>Another difference is parameter assignment --
[…]
>$ a=foo exec </dev/stdin

I think this is a known POSIX violation in GNU bash (though,
some of those can be worked around by putting it into POSIX
mode); ormaaj can probably say more on that if interested.

>The mksh man page says, "the assignments are in effect only for the 
>duration of the command". In bash you might do,

Yes, that’s POSIX-mandated for special builtin utilities
or somesuch-worded.

>So is ":" a NOP, or is it a builtin command? Beats me!

“:” is a builtin utility and the same as “true”, except
that “:” is “a POSIX special builtin” and “true” is
“a POSIX regular builtin” (see mkshbuiltins[] in funcs.c).

>Anyway, I'm picking nits. Here's where the rubber hits the road:
>
>  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM     TIME+ COMMAND           
>  
>12457 fthain    20   0  3524 1872 1572 S  0.0  0.1   0:00.01 bash              
> 
>12734 fthain    20   0  2228  712  608 S  0.0  0.0   0:00.00 mksh              
> 
>
>$ ls -l /bin/mksh /bin/bash
>-rwxr-xr-x 1 root root 263860 Mar 29 12:51 /bin/mksh
>-rwxr-xr-x 1 root root 720796 Sep  3  2012 /bin/bash

Don’t forget that GNU bash is probably dynamically linked
against libreadline and libncurses/libtermcap to boot.

Oh, and try mksh-static (on Debian) or roll your own;
on a Linux target, klibc (though you’ll need version 2.x
to get some bugfixes), dietlibc and bionic are all valid
targets (not µClibc, but that’s because it’s a horrid
bloated mess, not unlike (e)glibc itself). Just make sure
it passes the mksh testsuite (which is a good testsuite
for the compiler/toolchain/libc used, too – it finds more
bugs in those than in mksh; a recent example can be seen
at https://bugzilla.redhat.com/show_bug.cgi?id=922974 in
GCC, which is a known repeat offender).

Even without -DMKSH_SMALL it’s great – plus, not having to
do all the relocation and other stuff involved in dynamic
linking, there’s benefit, for example in the amount of CPU
instructions required to just run $SHELL -c true; read up
on http://k1024.org/~iusty/blog/entry/perf-null/ in case
you’re interested; tl;dr in cycles/instructions for shells:
bash 1680/1044K mksh 1258/942K dash 766/469K
mksh-static 502/322K (though with -DMKSH_SMALL), and that
was before my optimisations based on those numbers (e.g.
I did get the number of branch misses down *a lot*, as
well as the number of cycles for mksh-static.

>So thanks for the excellent work!

You’re welcome!

bye,
//mirabilos
-- 
[DJBDNS Zone] TTL 86400 – <Natureshadow> kann man da auch 1d schreiben?
<mirabilos> nö, außerdem kann ein Deutscher oder ein Japaner mit 1d
    ja erstmal nix anfangen, oder könntest du 1日 im zone file lesen?
<Natureshadow> das heißt für mich: ein Regal, das u.U. schiefstehen könnte

Reply via email to