You are not logged in.

#1 2017-06-08 19:39:59

Head_on_a_Stick
Member
From: London
Registered: 2015-09-29
Posts: 9,093
Website

MirBSD™ Korn Shell (mksh) 56b-1 backport

Quick link: https://software.opensuse.org//download … ckage=mksh

Repositories (with original source code): https://download.opensuse.org/repositor … unsenLabs/

Why use mksh?

Because it's faster, smaller, lighter [1] and more secure [2] than bash and loses none of the features (apart from associative arrays).

smile

[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

#2 2017-06-08 20:25:16

DeepDayze
Like sands through an hourglass...
From: In Linux Land
Registered: 2017-05-28
Posts: 1,901

Re: MirBSD™ Korn Shell (mksh) 56b-1 backport

Cool I should try it out. Thanks!


Real Men Use Linux

Offline

#3 2017-06-08 20:29:54

Head_on_a_Stick
Member
From: London
Registered: 2015-09-29
Posts: 9,093
Website

Re: MirBSD™ Korn Shell (mksh) 56b-1 backport

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

#4 2017-06-08 21:07:13

DeepDayze
Like sands through an hourglass...
From: In Linux Land
Registered: 2017-05-28
Posts: 1,901

Re: MirBSD™ Korn Shell (mksh) 56b-1 backport

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

#5 2017-06-08 21:11:48

Head_on_a_Stick
Member
From: London
Registered: 2015-09-29
Posts: 9,093
Website

Re: MirBSD™ Korn Shell (mksh) 56b-1 backport

^ Not that I know of, sorry.

General comparison here (with some tips):

https://www.mirbsd.org/mksh_old.htm#contrib

Offline

#6 2017-06-09 04:59:09

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 12,654
Website

Re: MirBSD™ Korn Shell (mksh) 56b-1 backport

Head_on_a_Stick wrote:

...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 )

Introduction to the Bunsenlabs Boron Desktop

Offline

#7 2017-06-09 06:22:50

Head_on_a_Stick
Member
From: London
Registered: 2015-09-29
Posts: 9,093
Website

Re: MirBSD™ Korn Shell (mksh) 56b-1 backport

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!

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...

roll

Last edited by Head_on_a_Stick (2017-06-10 14:23:25)

Offline

#8 2017-06-09 06:53:40

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 12,654
Website

Re: MirBSD™ Korn Shell (mksh) 56b-1 backport

Head_on_a_Stick wrote:
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 )

Introduction to the Bunsenlabs Boron Desktop

Offline

#9 2017-06-09 06:57:46

Head_on_a_Stick
Member
From: London
Registered: 2015-09-29
Posts: 9,093
Website

Re: MirBSD™ Korn Shell (mksh) 56b-1 backport

johnraff wrote:

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...

sad

----

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

#10 2017-06-09 07:03:38

brontosaurusrex
Middle Office
Registered: 2015-09-29
Posts: 2,746

Re: MirBSD™ Korn Shell (mksh) 56b-1 backport

Does it have floating point math like dtksh?

Offline

#11 2017-06-09 07:07:03

Head_on_a_Stick
Member
From: London
Registered: 2015-09-29
Posts: 9,093
Website

Re: MirBSD™ Korn Shell (mksh) 56b-1 backport

brontosaurusrex wrote:

Does it have floating point math like dtksh?

Diproton: ~ $ print $((1.1+1.1))
2.2
Diproton: ~ $

8)

Offline

#12 2017-06-09 10:46:14

brontosaurusrex
Middle Office
Registered: 2015-09-29
Posts: 2,746

Re: MirBSD™ Korn Shell (mksh) 56b-1 backport

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

? smile

Last edited by brontosaurusrex (2017-06-09 10:48:30)

Offline

#13 2017-06-09 11:40:53

Unia
Octo-portal-pussy
From: Stockholm, Sweden
Registered: 2015-09-17
Posts: 355
Website

Re: MirBSD™ Korn Shell (mksh) 56b-1 backport

^ 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

#14 2017-06-09 11:49:46

brontosaurusrex
Middle Office
Registered: 2015-09-29
Posts: 2,746

Re: MirBSD™ Korn Shell (mksh) 56b-1 backport

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

#15 2017-06-09 17:56:52

Head_on_a_Stick
Member
From: London
Registered: 2015-09-29
Posts: 9,093
Website

Re: MirBSD™ Korn Shell (mksh) 56b-1 backport

Head_on_a_Stick wrote:
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

#16 2017-06-10 01:04:39

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 12,654
Website

Re: MirBSD™ Korn Shell (mksh) 56b-1 backport

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 )

Introduction to the Bunsenlabs Boron Desktop

Offline

#17 2017-06-10 02:04:00

Sector11
Mod Squid Tpyo Knig
From: Upstairs
Registered: 2015-08-20
Posts: 8,028

Re: MirBSD™ Korn Shell (mksh) 56b-1 backport

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

#18 2017-06-10 02:19:48

DeepDayze
Like sands through an hourglass...
From: In Linux Land
Registered: 2017-05-28
Posts: 1,901

Re: MirBSD™ Korn Shell (mksh) 56b-1 backport

@S11, that sounds like a nice little trick to get around the lack of floating point arithmetic in mksh.


Real Men Use Linux

Offline

#19 2017-06-10 03:12:24

Sector11
Mod Squid Tpyo Knig
From: Upstairs
Registered: 2015-08-20
Posts: 8,028

Re: MirBSD™ Korn Shell (mksh) 56b-1 backport

Don't blame me, I found it on the web someplace.  I'm not that smart  smile

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

  yikes


Debian 12 Beardog, SoxDog and still a Conky 1.9er

Offline

#20 2017-06-10 13:02:39

brontosaurusrex
Middle Office
Registered: 2015-09-29
Posts: 2,746

Re: MirBSD™ Korn Shell (mksh) 56b-1 backport

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

Board footer

Powered by FluxBB