Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

Linux ports of OpenBSD's ksh

Share your HowTo, Documentation, Tips and Tricks. Not for support questions!.
Post Reply
Message
Author
User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 132 times

Linux ports of OpenBSD's ksh

#1 Post by Head_on_a_Stick »

Although bash is a fine shell with many useful features, it does have it's problems:
bash(1) wrote:BUGS
It's too big and too slow.
OpenBSD uses their own KornShell implementation (derived from the old public domain KornShell, pdksh) as the default shell, the codebase is much smaller than that of bash and benefits from the audits performed regularly by the developers. It uses less memory than bash and is also faster[1] but doesn't support here strings or numerical brace expansion; here documents & standard brace expansion work fine though.

There are two Linux ports of this program available:

https://github.com/ibara/oksh

https://github.com/dimkr/loksh

They both compile under Debian so I have packaged them up and added them to my OBS repository (the oksh package was ported by an OpenBSD developer and so should probably be favoured):

https://software.opensuse.org//download ... ckage=oksh

https://software.opensuse.org//download ... kage=loksh

To change the default interactive shell either run

Code: Select all

chsh -s /bin/oksh # or /bin/loksh
Or set loksh as the ksh alternative and use that instead:

Code: Select all

# update-alternatives --set ksh /bin/oksh
chsh -s /bin/ksh
The configuration file is set by $ENV so add this to ~/.profile and/or ~/.xsessionrc to make it read ~/.kshrc every time a shell is opened:

Code: Select all

export ENV="${HOME}/.kshrc"
Note that the command line editing mode is determined by $VISUAL (or $EDITOR if $VISUAL is unset) so if vim is preferred then add this line to ~/.kshrc to restore the usual behaviour (ie, up arrow to recall the history, etc):

Code: Select all

set -o emacs
[1] Output of ps_mem showing memory usage:

Code: Select all

580.0 KiB +  96.5 KiB = 676.5 KiB       ksh
  2.4 MiB + 216.5 KiB =   2.6 MiB       bash
Size of binaries:

Code: Select all

-rwxr-xr-x 1 root root 1.2M Jan 24 10:01 /bin/bash
-rwxr-xr-x 1 root root 264K Apr  9 19:13 /bin/ksh
Rough benchmark for loksh:

Code: Select all

$ time for i in $(seq 1 1000000);do [ 1 = 1 ];done
    0m01.96s real     0m01.90s user     0m00.09s system
Bash:

Code: Select all

$ time for i in $(seq 1 1000000);do [ 1 = 1 ];done

real    0m3.633s
user    0m3.586s
sys     0m0.061s
Bash with numerical brace expansion:

Code: Select all

$ time for i in {1..1000000};do [ 1 = 1 ];done

real    0m3.944s
user    0m3.876s
sys     0m0.064s
Last edited by Head_on_a_Stick on 2020-06-05 16:19, edited 2 times in total.
deadbang

User avatar
4D696B65
Site admin
Site admin
Posts: 2696
Joined: 2009-06-28 06:09
Been thanked: 85 times

Re: loksh: a Linux port of OpenBSD's ksh

#2 Post by 4D696B65 »

Correct me if I am wrong, I thought Debian dropped bash a long time ago and replaced it with dash.
A comparison between ksh and dash would be more useful

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 132 times

Re: loksh: a Linux port of OpenBSD's ksh

#3 Post by Head_on_a_Stick »

4D696B65 wrote:I thought Debian dropped bash a long time ago and replaced it with dash
Debian links /bin/sh to dash rather than bash, yes: https://wiki.debian.org/DashAsBinSh

But this thread is about using loksh as the default interactive shell instead of bash.

See also https://wiki.debian.org/Shell

It should be possible to re-link /bin/sh to loksh but I don't think I would recommend it.
4D696B65 wrote:A comparison between ksh and dash would be more useful
https://forum.archlabslinux.com/t/inter ... rison/2691
deadbang

User avatar
Bloom
df -h | grep > 90TiB
df -h | grep > 90TiB
Posts: 504
Joined: 2017-11-11 12:23
Been thanked: 26 times

Re: loksh: a Linux port of OpenBSD's ksh

#4 Post by Bloom »

And Debian does have a Korn shell in the repos: mksh (MirBSD Korn Shell)

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 132 times

Re: loksh: a Linux port of OpenBSD's ksh

#5 Post by Head_on_a_Stick »

^ There are several different KornShell implementations, Debian also has the original ksh93: https://packages.debian.org/stretch/ksh

The MirBSD™ Korn Shell does not share any code with ksh93 but both it and loksh are derived from the old pdksh package.

As I see it, the advantages of loksh over mksh are the GNU-style PS1 options, the support for bash-like keyboard shortcuts (such as <ctrl>+arrow to move the cursor across words rather than just spaces) and the fact that the codebase is from the OpenBSD developers and it is audited regularly by them.
deadbang

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 132 times

Re: loksh: a Linux port of OpenBSD's ksh

#6 Post by Head_on_a_Stick »

I've added a statically-linked version (useful for rescue situations in which /usr is not available) and configured the packages to use all of the Debian hardening flags (-fstack-protector-strong etc), version bumped to 6.4-2
deadbang

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 132 times

Re: loksh: a Linux port of OpenBSD's ksh

#7 Post by Head_on_a_Stick »

Version 6.4-3 is now out.

This package will actually install on machines that don't have usrmerge, which is nice.
deadbang

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 132 times

Re: loksh: a Linux port of OpenBSD's ksh

#8 Post by Head_on_a_Stick »

Version 6.5-1 is building now :)

It should be available soon.

EDIT: it's there now.

44 minutes after the upstream release, which was itself only a few hours after the OpenBSD 6.5 release; nice.
deadbang

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 132 times

Re: loksh: a Linux port of OpenBSD's ksh

#9 Post by Head_on_a_Stick »

Version 6.6-1 is now available.
deadbang

milomak
Posts: 2158
Joined: 2009-06-09 22:20
Been thanked: 1 time

Re: loksh: a Linux port of OpenBSD's ksh

#10 Post by milomak »

can i assume there is completion?
Desktop: A320M-A PRO MAX, AMD Ryzen 5 3600, GALAX GeForce RTX™ 2060 Super EX (1-Click OC) - Sid, Win10, Arch Linux, Gentoo, Solus
Laptop: hp 250 G8 i3 11th Gen - Sid
Kodi: AMD Athlon 5150 APU w/Radeon HD 8400 - Sid

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 132 times

Re: loksh: a Linux port of OpenBSD's ksh

#11 Post by Head_on_a_Stick »

Oh yes, I find it has all the features I need for day-to-day use. It's a bit austere compared to, for example, grml's sublime zsh configuration but it's faster, lighter and almost certainly less buggy.
deadbang

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 132 times

Re: loksh: a Linux port of OpenBSD's ksh

#12 Post by Head_on_a_Stick »

Version 6.7-1 of of the dynamically-linked loksh package is now available.

Upstream has switched from a Makefile to Meson and I have no idea how to make a statically-linked package with that so that will have to wait for me to upskill.

EDIT: there are no packages for Debian stretch because the Meson version is too old.
deadbang

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 132 times

Re: Linux ports of OpenBSD's ksh

#13 Post by Head_on_a_Stick »

I've added another port to the OP — it's called oksh and was created by Brian Callahan (also known as ibara), who is an OpenBSD developer.
deadbang

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 132 times

Re: Linux ports of OpenBSD's ksh

#14 Post by Head_on_a_Stick »

Version 6.8 of loksh is now available:

https://software.opensuse.org//download ... kage=loksh

I'm sure Dr. Callahan will have v6.8 of oksh out soon, I'll bump the thread when that happens.
deadbang

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 132 times

Re: Linux ports of OpenBSD's ksh

#15 Post by Head_on_a_Stick »

deadbang

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 132 times

Re: Linux ports of OpenBSD's ksh

#16 Post by Head_on_a_Stick »

Version 7.1 of loksh is building now and should be available soon.
deadbang

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 132 times

Re: Linux ports of OpenBSD's ksh

#17 Post by Head_on_a_Stick »

Version 7.1 of oksh is building now and should be available soon.
deadbang

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 132 times

Re: Linux ports of OpenBSD's ksh

#18 Post by Head_on_a_Stick »

The loksh package is currently uninstallable for systems which do not link /bin/ to /usr/bin/ (ie, that do not have the usrmerge package installed).

I'm working on the issue now but the best approach seems to be to persuade upstream to change the default install path to /bin/loksh rather than /usr/bin/loksh. That would work on both usrmerge and non-merged systems. Upstream might not agree though.

If a working 7.1 version of OpenBSD's ksh is required for a non-merged system install the oksh package instead until I fix this. Apologies for the inconvenience.
deadbang

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 132 times

Re: Linux ports of OpenBSD's ksh

#19 Post by Head_on_a_Stick »

Changed my mind and just fixed the postinst & prerm scripts instead. The binary is still in the "wrong" location but I'll address that at a later date.

Version 7.1-2 of loksh is building now and should be available soon.
deadbang

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 132 times

Re: Linux ports of OpenBSD's ksh

#20 Post by Head_on_a_Stick »

Version 7.3-1 of both oksh and loksh have been available for a while now but I was still sulking :mrgreen:

The OBS has updated their Debian repositories so bookworm packages are now available in their "Debian 12" repositories.

Links in the OP, as usual.
deadbang

Post Reply