You are not logged in.
Quick link: https://software.opensuse.org//download … ckage=mksh
Repositories (with original source code): https://download.opensuse.org/repositor … unsenLabs/
Because it's faster, smaller, lighter [1] and more secure [2] than bash and loses none of the features (apart from associative arrays).
[1] I used a very basic benchmark:
shellbench() {
time -p "$@" -c 'for i in $(seq 1 1000000);do [ 1 = 1 ];done'
}
for sh in bash zsh mksh ksh93 dash;do shellbench "$sh";echo "On disk: $(ls -lah /bin/$sh|awk '{print $5}')";echo "Memory: $(/bin/su -c 'ps-mem'|grep $sh)\n";done
With these results:
real 2.84
user 2.81
sys 0.04
On disk: 1.1M
Memory: 2.8 MiB + 192.5 KiB = 2.9 MiB bash
real 2.25
user 1.90
sys 0.35
On disk: 801K
Memory: 2.1 MiB + 221.0 KiB = 2.3 MiB zsh
real 1.42
user 1.42
sys 0.01
On disk: 263K
Memory: 380.0 KiB + 190.0 KiB = 570.0 KiB mksh
real 0.53
user 0.51
sys 0.02
On disk: 1.6M
Memory: 1.7 MiB + 132.0 KiB = 1.8 MiB ksh93
real 0.93
user 0.91
sys 0.02
On disk: 115K
Memory: 92.0 KiB + 71.5 KiB = 163.5 KiB dash
ksh93 is blisteringly fast but sadly (semi-)unmaintained, otherwise I think mksh has it, for interactive use anyway.
[2] mksh is the default shell for Android since version 4.0 because of the speed, size & security advantages.
EDIT: more details
Last edited by Head_on_a_Stick (2017-10-28 12:43:20)
Offline
Cool I should try it out. Thanks!
Real Men Use Linux
Offline
To change the default interactive and login shell, run this command:
chsh
Because Debian has both mksh and ksh93 available, I prefer to set this to /bin/ksh and link that to mksh by using:
sudo update-alternatives --config ksh
There is an example configuration file that can be copied to $HOME and edited:
zcat /usr/share/doc/mksh/examples/dot.mkshrc.gz > ~/.mkshrc
This provides a nice prompt and some handy functions (including popd & pushd).
Offline
Any tools to translate bash scripts to mksh?
Last edited by Head_on_a_Stick (2017-06-08 21:09:46)
Real Men Use Linux
Offline
^ Not that I know of, sorry.
General comparison here (with some tips):
Offline
...loses none of the features (apart from associative arrays).
But... I love associative arrays!
If I want a no-frills shell I just invoke sh (ie dash).
I guess mksh falls somewhere in between.
...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), now on Bluesky, there's also some GitStuff )
Offline
Head_on_a_Stick wrote:...loses none of the features (apart from associative arrays).
But... I love associative arrays!
Ah, good news then — I was mistaken!
From the man page Variable Assignments section:
[nonsense redacted]
I think this was added at or about R42 so I don't know why I thought it was missing (perhaps because I've never used associative arrays).
EDIT: read the wrong man page, what a p***k...
Last edited by Head_on_a_Stick (2017-06-10 14:23:25)
Offline
johnraff wrote:Head_on_a_Stick wrote:...loses none of the features (apart from associative arrays).
But... I love associative arrays!
Ah, good news then — I was mistaken!
Er... weren't you saying that the only Bash feature lacking in mksh was AA's? I was saying that that's a feature of bash that I love. I've no idea whether mksh supports them...
...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), now on Bluesky, there's also some GitStuff )
Offline
Er... weren't you saying that the only Bash feature lacking in mksh was AA's?
No, sorry for the confusion, I thought that mksh didn't support AAs but it apparently does.
EDIT: wrong again, stick man...
----
I did try to replace the bash shebang in the bl-scripts and pipemenus with mksh just to test any speed gain but there were some errors that I haven't had the time (or skill) to track down :8
Last edited by Head_on_a_Stick (2017-06-10 14:24:17)
Offline
Does it have floating point math like dtksh?
Offline
Does it have floating point math like dtksh?
Diproton: ~ $ print $((1.1+1.1))
2.2
Diproton: ~ $
8)
Offline
apt-cache policy mksh
mksh:
Installed: 54-2+b4
Candidate: 54-2+b4
Version table:
*** 54-2+b4 500
500 https://deb.debian.org/debian stretch/main amd64 Packages
100 /var/lib/dpkg/status
$ print $((1/2))
0
?
Last edited by brontosaurusrex (2017-06-09 10:48:30)
Offline
^ Probably 1 and 2 are recognized as integers and hence it is doing integer division. Try 1.0 and 2.0.
If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres
Offline
Dunno, probably a syntax problem
$ print $((1.00/2.00))
mksh: 1.00/2.00: unexpected '.'
$ print $((1.00 / 2.00))
mksh: 1.00 / 2.00: unexpected '.'
$ print $((1,00 / 2,00))
0
Offline
brontosaurusrex wrote:Does it have floating point math like dtksh?
Diproton: ~ $ print $((1.1+1.1)) 2.2 Diproton: ~ $
8)
Erm, sorry folks but I forgot that I changed /bin/ksh to ksh93 (which does support floating point arithmetic) :8
MirBSD™ Korn Shell does not support that, apologies for the misinformation.
From the horse's mouth:
This is the homepage of the MirBSD Korn Shell (mksh), which is the actively developed successor of pdksh. The focus is a compact yet featureful shell, so several of the ksh93/bash/zsh extensions are present, while others, such as floating point arithmetic, will not be provided, even though the aim is as generic as ksh93’s (interactive and script use; embedding is not yet possible) and to be very portable, also to include some extensions of its own. It’s Unicode aware.
(Emphasis mine)
Offline
I haven't yet been able to find any hint that mksh supports associative arrays btw.
...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), now on Bluesky, there's also some GitStuff )
Offline
Why not just use bc?
~/bin/calc
#!/bin/bash
# calc
bc << END
scale=5
$@
END
09 Jun 17 @ 22:55:52 ~
$ calc 1.1+1.1
2.2
09 Jun 17 @ 23:04:21 ~
$ calc 1.00 / 2.00
.50000
Debian 12 Beardog, SoxDog and still a Conky 1.9er
Offline
@S11, that sounds like a nice little trick to get around the lack of floating point arithmetic in mksh.
Real Men Use Linux
Offline
Don't blame me, I found it on the web someplace. I'm not that smart
Went looking because I hate the GUI calculators and xcalc is f... not pretty. And since I'm spending more time in a terminal as time passes this makes sense - even S12 uses it on occasion.
I get dizzy reading
man bc
Debian 12 Beardog, SoxDog and still a Conky 1.9er
Offline
Bc behaves differently than I would expect (rounding). Good option for such scripts is python I guess.
Bc rounding https://github.com/brontosaurusrex/post … olCont#L46 example. This specific + 0.5 only survives positive numbers thought. I guess workaround would be to do a nice bc calc function that fixes all that....
All this is for a new thread.
Last edited by brontosaurusrex (2017-06-10 22:36:09)
Offline