loksh: a Linux port of OpenBSD's ksh

Share your own howto's etc. Not for support questions!

loksh: a Linux port of OpenBSD's ksh

Postby Head_on_a_Stick » 2019-04-12 16:19

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 is a Linux port of this program available:

https://github.com/dimkr/loksh

It compiles under Debian so I have packaged it up and added it to my OBS repository:

https://software.opensuse.org//download.html?project=home%3AHead_on_a_Stick%3Aloksh&package=loksh

Statically-linked version here:

https://software.opensuse.org//download ... ksh-static

To change the default interactive shell either run
Code: Select all
chsh -s /bin/loksh

Or set loksh as the ksh alternative and use that instead:
Code: Select all
# update-alternatives --set ksh /bin/loksh
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 2019-04-14 08:01, edited 1 time in total.
Don't break DebianHow to report bugs

SharpBang GNU/Linux — a pre-configured Openbox/Tint2 desktop running on Debian stable
User avatar
Head_on_a_Stick
 
Posts: 10675
Joined: 2014-06-01 17:46
Location: /dev/chair

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

Postby 4D696B65 » 2019-04-12 16:38

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
4D696B65
 
Posts: 2439
Joined: 2009-06-28 06:09

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

Postby Head_on_a_Stick » 2019-04-12 16:51

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
Don't break DebianHow to report bugs

SharpBang GNU/Linux — a pre-configured Openbox/Tint2 desktop running on Debian stable
User avatar
Head_on_a_Stick
 
Posts: 10675
Joined: 2014-06-01 17:46
Location: /dev/chair

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

Postby Bloom » 2019-04-13 08:00

And Debian does have a Korn shell in the repos: mksh (MirBSD Korn Shell)
User avatar
Bloom
 
Posts: 194
Joined: 2017-11-11 12:23

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

Postby Head_on_a_Stick » 2019-04-13 08:38

^ 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.
Don't break DebianHow to report bugs

SharpBang GNU/Linux — a pre-configured Openbox/Tint2 desktop running on Debian stable
User avatar
Head_on_a_Stick
 
Posts: 10675
Joined: 2014-06-01 17:46
Location: /dev/chair

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

Postby Head_on_a_Stick » 2019-04-14 08:02

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
Don't break DebianHow to report bugs

SharpBang GNU/Linux — a pre-configured Openbox/Tint2 desktop running on Debian stable
User avatar
Head_on_a_Stick
 
Posts: 10675
Joined: 2014-06-01 17:46
Location: /dev/chair

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

Postby Head_on_a_Stick » 2019-04-21 13:12

Version 6.4-3 is now out.

This package will actually install on machines that don't have usrmerge, which is nice.
Don't break DebianHow to report bugs

SharpBang GNU/Linux — a pre-configured Openbox/Tint2 desktop running on Debian stable
User avatar
Head_on_a_Stick
 
Posts: 10675
Joined: 2014-06-01 17:46
Location: /dev/chair

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

Postby Head_on_a_Stick » 2019-04-24 20:05

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.
Don't break DebianHow to report bugs

SharpBang GNU/Linux — a pre-configured Openbox/Tint2 desktop running on Debian stable
User avatar
Head_on_a_Stick
 
Posts: 10675
Joined: 2014-06-01 17:46
Location: /dev/chair

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

Postby Head_on_a_Stick » 2019-10-18 21:01

Version 6.6-1 is now available.
Don't break DebianHow to report bugs

SharpBang GNU/Linux — a pre-configured Openbox/Tint2 desktop running on Debian stable
User avatar
Head_on_a_Stick
 
Posts: 10675
Joined: 2014-06-01 17:46
Location: /dev/chair

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

Postby milomak » 2019-10-18 21:43

can i assume there is completion?
Desktop: iMac Late-2015 27" 5K Retina (17,1 - 3.3GHz) - MacOS and Windows 10 (Bootcamp)/ Sid (External SSD)
Laptop: Lenovo ideapad Y700 [nVidia Optimus] (64-bit) - Sid, Win10, Solus
Kodi Box: AMD Athlon 5150 APU w/Radeon HD 8400 - Sid
milomak
 
Posts: 1998
Joined: 2009-06-09 22:20

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

Postby Head_on_a_Stick » 2019-10-19 08:46

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.
Don't break DebianHow to report bugs

SharpBang GNU/Linux — a pre-configured Openbox/Tint2 desktop running on Debian stable
User avatar
Head_on_a_Stick
 
Posts: 10675
Joined: 2014-06-01 17:46
Location: /dev/chair


Return to Docs, Howtos, Tips & Tricks

Who is online

Users browsing this forum: No registered users and 10 guests

fashionable