The officially official Devuan Forum!

You are not logged in.

#1 2019-04-10 16:59:46

Head_on_a_Stick
Member
From: London
Registered: 2019-03-24
Posts: 3,125  
Website

Linux ports of OpenBSD's ksh

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 compile under Devuan so I have packaged them up and added it 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

The repositories are technically for Debian but they should be compatible with Devuan and they only hold the loksh packages, there are absolutely no systemd dependencies at all.

The package currently conflicts with ksh93 because the binaries share the same name but I am researching how to change the name of the installed binary so I can remove the conflict (any hints welcomed), I will update the package when I figure it out. Fixed!

To change the default interactive shell run

chsh -s /bin/oksh # or /bin/loksh

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:

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

set -o emacs

[1] Output of ps_mem showing memory usage:

580.0 KiB +  96.5 KiB = 676.5 KiB       ksh
  2.4 MiB + 216.5 KiB =   2.6 MiB       bash

Size of binaries:

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

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

Bash:

$ 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:

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

real    0m3.944s
user    0m3.876s
sys     0m0.064s

EDIT: added oksh port.

Last edited by Head_on_a_Stick (2020-06-05 16:44:38)


Brianna Ghey — Rest In Power

Offline

#2 2019-04-11 13:39:34

cynwulf
Member
Registered: 2017-10-09
Posts: 234  

Re: Linux ports of OpenBSD's ksh

Having a conflicts stanza in the control file, which you should have if you want to distribute this (I haven't checked) is not going to work as a long term solution.  You will be better served with some renaming (prefixing) of binaries and perhaps an install target in /usr/local - end user can then just set up aliases as necessary and there's much less danger of your 3rd party package clobbering anything from official repos.

Offline

#3 2019-04-11 14:39:49

Head_on_a_Stick
Member
From: London
Registered: 2019-03-24
Posts: 3,125  
Website

Re: Linux ports of OpenBSD's ksh

^ Thank you very much cynwulf, that is excellent advice.

And I've just realised that my package breaks the ksh alternative as well because it overwrites it...

I will try to patch the Makefile, I think that's the way forward here.


Brianna Ghey — Rest In Power

Offline

#4 2019-04-11 15:11:21

Head_on_a_Stick
Member
From: London
Registered: 2019-03-24
Posts: 3,125  
Website

Re: Linux ports of OpenBSD's ksh

Quilt rocks!

Patched the Makefile to rename the binary to /bin/loksh and added loksh to the ksh alternative system.

The package no longer conflicts with ksh93 and can be safely co-installed smile

New version is 6.4-1.1:

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

To set it as the default shell use either

chsh -s /bin/loksh

Or use /bin/ksh instead and also run

update-alternatives --set ksh /bin/loksh

to set loksh as the /bin/ksh alternative.

Last edited by Head_on_a_Stick (2019-04-11 15:21:44)


Brianna Ghey — Rest In Power

Offline

#5 2019-04-13 23:05:30

Head_on_a_Stick
Member
From: London
Registered: 2019-03-24
Posts: 3,125  
Website

Re: Linux ports of OpenBSD's ksh

Added a statically-linked version (useful for rescue situations in which /usr is not available) and also included all the hardening flags (-fstackprotector-strong etc), version bumped to 6.4-2


Brianna Ghey — Rest In Power

Offline

#6 2019-04-20 18:20:36

Head_on_a_Stick
Member
From: London
Registered: 2019-03-24
Posts: 3,125  
Website

Re: Linux ports of OpenBSD's ksh

Version 6.4-3 is out.

I made a mistake (again) with the binary location that broke the alternatives and I didn't notice 'cos my systems are /usr-merged.

It's fixed now.

OpenBSD 6.5 is due out very soon so I think we'll see v6.5 of loksh shortly afterwards.


Brianna Ghey — Rest In Power

Offline

#7 2019-04-24 20:53:10

Head_on_a_Stick
Member
From: London
Registered: 2019-03-24
Posts: 3,125  
Website

Re: Linux ports of OpenBSD's ksh

Version 6.5-1 is building now smile

It should be available soon.

EDIT: now in the repository.

Last edited by Head_on_a_Stick (2019-04-24 20:56:23)


Brianna Ghey — Rest In Power

Offline

#8 2019-10-18 19:46:02

Head_on_a_Stick
Member
From: London
Registered: 2019-03-24
Posts: 3,125  
Website

Re: Linux ports of OpenBSD's ksh

Version 6.6-1 is now available.

I've tidied up the packaging a bit so Lintian now only complains about the embedded ncurses library in the statically-linked version.


Brianna Ghey — Rest In Power

Offline

#9 2020-05-22 22:20:10

Head_on_a_Stick
Member
From: London
Registered: 2019-03-24
Posts: 3,125  
Website

Re: Linux ports of OpenBSD's ksh

Version 6.7-1 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.


Brianna Ghey — Rest In Power

Offline

#10 2020-05-23 14:35:18

siva
Member
Registered: 2018-01-25
Posts: 282  

Re: Linux ports of OpenBSD's ksh

how tf did I miss this?

Thanks hoas.

Last edited by siva (2020-05-23 14:35:26)

Offline

#11 2020-05-23 16:41:04

golinux
Administrator
Registered: 2016-11-25
Posts: 3,316  

Re: Linux ports of OpenBSD's ksh

siva wrote:

how tf did I miss this?.

Because you're barely a shadow here these days.  You have been missed!

Online

#12 2020-05-23 18:07:03

Head_on_a_Stick
Member
From: London
Registered: 2019-03-24
Posts: 3,125  
Website

Re: Linux ports of OpenBSD's ksh

v6.7.1-1 is now available, upstream has included the lolibc subproject in the release tarball so I don't have to hack it in like I did for v6.7-1. I've also moved libncurses6 to the Recommends list because it is now an optional dependency.

I've decided to drop the loksh-static package, I can't get it to build and it's a potential security risk if I miss an update for the embedded libraries.

I forgot to mention but there are no ASCII packages because Meson builds aren't supported by that release's debhelper version. Sorry.


Brianna Ghey — Rest In Power

Offline

#13 2020-05-24 15:10:37

HevyDevy
Member
Registered: 2019-09-06
Posts: 358  

Re: Linux ports of OpenBSD's ksh

what is the benefit of this loksh over say mksh or ksh in the repos as it stands, updated and maintained i suppose?

-rwxr-xr-x 1 root root 275K May 24 21:30 /bin/mksh*

https://packages.debian.org/buster/mksh

Last edited by HevyDevy (2020-05-24 15:20:13)

Offline

#14 2020-05-24 15:29:10

Head_on_a_Stick
Member
From: London
Registered: 2019-03-24
Posts: 3,125  
Website

Re: Linux ports of OpenBSD's ksh

The loksh package is derived from OpenBSD's KornShell implementation and so is audited and maintained by their devs.

It is very slightly "lighter" than mksh and also a tiny bit faster but it lacks support for here strings (here documents still work though). In respect of the original KornShell, that is significantly faster (it is the fastest of all the Bourne shells by some margin) but the ksh93 version in ASCII & beowulf is very old and has quite a few bugs — the new 2020 version in chimera/ceres fixes most of these and is under heavy development.

All three KornShell implementations are actively developed and maintained.

EDIT: loksh is the only one with bash-style PS1 support though, which I like.

Last edited by Head_on_a_Stick (2020-05-24 15:31:01)


Brianna Ghey — Rest In Power

Offline

#15 2020-05-24 16:15:24

HevyDevy
Member
Registered: 2019-09-06
Posts: 358  

Re: Linux ports of OpenBSD's ksh

Yeah i use openbsd on another machine, 6.7 has proved to be really good performance wise on my intel gear.

Would be nice to see debian pick up loksh in testing.

I see alpine linux and some other musl libc based distros have picked this up, i actually dual boot alpine and openbsd on said machine so will have to install loksh on alpine wink

Last edited by HevyDevy (2020-05-24 16:16:32)

Offline

#16 2020-05-24 22:40:57

siva
Member
Registered: 2018-01-25
Posts: 282  

Re: Linux ports of OpenBSD's ksh

golinux wrote:
siva wrote:

how tf did I miss this?.

Because you're barely a shadow here these days.  You have been missed!

^_^

Head_on_a_Stick wrote:

Statically-linked version here...

I tried following the link and it said the file isn't found sad

Offline

#17 2020-05-24 23:33:52

Head_on_a_Stick
Member
From: London
Registered: 2019-03-24
Posts: 3,125  
Website

Re: Linux ports of OpenBSD's ksh

I've removed the statically-linked version, I can't get it to build under Meson and it's a potential security risk anyway.

The mksh package provides two statically linked versions using musl & klibc, both of which are better than glibc (which has problems with static linking) and Thorsten is a *much* better maintainer than I so use that if you need a KornShell for rescue & recovery purposes.


Brianna Ghey — Rest In Power

Offline

#18 2020-05-25 20:27:52

Head_on_a_Stick
Member
From: London
Registered: 2019-03-24
Posts: 3,125  
Website

Re: Linux ports of OpenBSD's ksh

OT for this thread but hey ho...

I wrote:

the new 2020 version in chimera/ceres fixes most of these and is under heavy development.

I've just backported that version of the original KornShell to beowulf:

https://software.opensuse.org//download … ackage=ksh

It's building now, should be ready soon.


Brianna Ghey — Rest In Power

Offline

#19 2020-05-26 16:20:07

HevyDevy
Member
Registered: 2019-09-06
Posts: 358  

Re: Linux ports of OpenBSD's ksh

What are the differences in your backport to the locally available ksh in stable/testing ?

Offline

#20 2020-05-26 19:53:16

Head_on_a_Stick
Member
From: London
Registered: 2019-03-24
Posts: 3,125  
Website

Re: Linux ports of OpenBSD's ksh

The AT&T KornShell version in beowulf is ksh93, which is old and buggy. My backport is ksh2020, which is shiny and (mostly) fixed.


Brianna Ghey — Rest In Power

Offline

#21 2020-06-05 16:57:43

Head_on_a_Stick
Member
From: London
Registered: 2019-03-24
Posts: 3,125  
Website

Re: Linux ports of OpenBSD's ksh

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.


Brianna Ghey — Rest In Power

Offline

#22 2020-09-27 14:49:48

Head_on_a_Stick
Member
From: London
Registered: 2019-03-24
Posts: 3,125  
Website

Re: Linux ports of OpenBSD's ksh

Version 6.7.4 of loksh is building now, it should be available soon:

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

@ibara has oksh v6.7.1 available but it's a pre-release and the only change is for cross-compilation support so I'm not updating the packages. OpenBSD 6.8 should be out soon and I will update oksh to that version as soon as it is available.


Brianna Ghey — Rest In Power

Offline

#23 2020-10-23 17:29:39

Head_on_a_Stick
Member
From: London
Registered: 2019-03-24
Posts: 3,125  
Website

Re: Linux ports of OpenBSD's ksh

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.


Brianna Ghey — Rest In Power

Offline

#24 2020-11-01 10:43:11

Head_on_a_Stick
Member
From: London
Registered: 2019-03-24
Posts: 3,125  
Website

Re: Linux ports of OpenBSD's ksh


Brianna Ghey — Rest In Power

Offline

#25 2021-01-09 22:05:13

ifdv44
Member
Registered: 2021-01-03
Posts: 10  

Re: Linux ports of OpenBSD's ksh

Head_on_a_Stick wrote:

The loksh package is derived from OpenBSD's KornShell implementation and so is audited and maintained by their devs.

It is very slightly "lighter" than mksh and also a tiny bit faster but it lacks support for here strings (here documents still work though). In respect of the original KornShell, that is significantly faster (it is the fastest of all the Bourne shells by some margin) but the ksh93 version in ASCII & beowulf is very old and has quite a few bugs — the new 2020 version in chimera/ceres fixes most of these and is under heavy development.

All three KornShell implementations are actively developed and maintained.

EDIT: loksh is the only one with bash-style PS1 support though, which I like.

Any quick and easy reference to the pros/cons of the three? I'm a KSH user at heart and haven't got to installing it and configuring it how i want yet so am open to improvements .

Offline

Board footer