The MirBSD Korn Shell

Sponsored by
SpeedPartner logo

Table of Contents

mksh(1) R40d

This is the website of the MirBSD™ Korn Shell, an actively developed free implementation of the Korn Shell programming language and a successor to the Public Domain Korn Shell (pdksh).

mksh Logo This page is always accessible via a redirection at http://mirbsd.de/mksh, which is the canonical homepage URI. There also is (most of the time) mksh on Freshmeat and an mksh project page on ohlol, a statistics site. mksh is experimentally tracked at Launchpad. Download the Logo as SVG if you want. There’s also a full licence terms overview.

Introduction

The current version of mksh is mksh R40d from 11 December 2011.

Thanks to “Der Verein trash.net” for sponsoring access to a Solaris 8 box. Thanks to Julian “yofuh” Wiesener for just another account on a Sun E420 on Solaris 11β. Thanks to someone who prefers to stay anonymous due to tons of red tape for providing access to an AIX 5.3 system with gcc and xlC installed. (Both are now defunct.) Thanks to Jupp “cnuke” Söntgen for building on AIX in Dresden nowadays. Thanks to HP TestDrive/PvP/DSPP/CLOE, which helps in keeping mksh portable to several Unixes and compilers, and track down some architecture- or glibc-specific bugs. (These days, HP-UX/IA64 only, though.) Thanks to gnubber’s admin (Barry “bddebian” deFreese), as well as Samuel “youpi” Thibault, for providing shell access to a Debian GNU/Hurd system. Thanks to Lucas “laffer1” Holt for ssh access to the MidnightBSD server. Thanks to Waldemar “wbx” Brodkorb for dropping his unused Zaurus SL-C3200 to someone who can actually make use of it to test mksh on OpenBSD. Thanks to Andreas “gecko2” Gockel for access to a couple of Debian and Macintosh boxen and an iPhone 3G. Thanks to Martin Zobel-Helas for an account on an Alpha system. Thanks to Bastian “waldi” Blank for access to an S/390 system and uploading mksh packages to Debian for quite some time. Also thanks to Otavio Salvador and Patrick “aptituz” Schönfeld for uploading a couple of my Debian packages. The Debian GNU/k*BSD and Hurd developers were quite helpful in assisting and testing as well. Thanks to Thomas E. “TGEN” Spanjaard for access to both a NetBSD and a DragonFly system. Thanks to Josef “jupp” / “penpen” Schugt for testing mksh on a Digital Unix (OSF/1 V4.0) system from the Uni Bonn Physik CIP Pool. Thanks to DEChengst from #UnixNL for providing access to a HP/Compaq Tru64 (OSF/1 V5.1B) system, an OSF/1 V2.0 system and an Ultrix 4.5 system. Thanks to Adam “replaced” Hoka for a BSDi BSD/OS 3.1 ISO9660 image and offering to help with HP-sUX testing (now that HP TestDrive went down) and initial porting to Haiku, which was continued at CLT 2010 with help from Stephan Aßmus. Thanks to André “naaina” Wösten for ssh on a QNX box. Thanks to Olivier Duchateau for testing on Slackware and Zenwalk GNU/Linux. Thanks to Winston W. for spotting musl, and thanks to maximilian attems and H. Peter Anvin for almost fixing klibc. Thanks to RT|Chatzilla, Chris “ir0nh34d” Sutcliffe, and others for Win32 platform assistance. (Did I miss anyone? Mail me if so. Some of these are past, anyway.)

What is mksh(1)? – Short answer: The MirBSD Korn Shell. Okay, but what exactly does it do, or why another shell? These questions will be answered here for the people interested. Right now, you only need to know that mksh is a DFSG-free and OSD-compliant (and OSI approved) successor to pdksh, developed as part of the MirOS Project as native Bourne/POSIX/Korn shell for MirOS BSD, but also to be readily available under other UNIX®-like operating systems.

The source code for mksh is available at the MirOS Project mirrors as well as these of other operating system projects due to being included in these; however, we do not provide binaries. Find instructions to build and install mksh below, or ask your operating environment vendor to package and include mksh; we provide assistance for this task if asked. Licencing permits this as long as due credit is given to the authors and contributors and the copyright notices are not removed in their entirety; modifying is allowed (but if the result is still called mksh, it’s discouraged; talk with us if you feel you have to modify mksh). The individual licences used are the MirOS licence, and (for BSD compatibility on other operating systems) the 3-clause UCB licence and the ISC licence; full terms are available. pdksh originally was public domain, with a few exceptions, but these files are not part of mksh R21 or up. The mksh(1) author (mirabilos) acknowledges the contributions of these people who dedicated pdksh and oksh to the public, and asserts a collective copyright on the code. All these licences are DFSG clean and conform to the OSD, and the MirOS Licence is listed on the pages of the ifrOSS licence centre as well as in the FSF/UNESCO Directory of Free Software. The MirBSD Korn Shell is OSI Certified Open Source Software™ and its manual is Open Knowledge.

To compile mksh, you will need a Bourne or POSIX shell (Solaris /bin/sh is enough, and the Z shell should work), a C compiler (at the moment, only the one from the GNU Compiler Collection works, but we’re attempting to change this), system and C library header files and the standard C runtime. You will also need a set of standard UNIX® tools on a supported operating system: any recent BSD; Darwin, Apple Mac OSX; Interix (Microsoft® Services for Unix 3.5, maybe Subsystem for Unix Applications on Win2003/Vista); GNU/Cygwin; UWIN; GNU/Linux (libc5, glibc, dietlibc, µClibc, some klibc systems are tested), Debian GNU/kFreeBSD, GNU/Hurd or GNU/Linux; Sun Solaris (8, 9, 10, 11), OpenSolaris; AIX; IRIX; HP-UX 11i; OSF/1; ULTRIX; Minix 3
To run the regression test suite, you will need a not too antiquated Perl with POSIX.pm as well as /bin/ed (whose installation is strongly suggested anyway, because it’s the standard FCEDIT history editor and standard UNIX® text editor), as well as a controlling terminal, usually /dev/tty or provided from script(1) or GNU screen.

To use mksh, you only need the C runtime (and any supplemental libraries the binary was linked against) and, optionally, /bin/ed – for interactive use, a controlling terminal is highly recommended because job control does not work without one.

To make full use of mksh(1)’s interactive features, it is recommended to copy the dot.mkshrc file from the source distribution as ~/.mkshrc into the user’s home directory and let the user adjust it to suit his needs. The sample file configures a few aliases and shell functions as well as a sensible prompt ($PS1) and some csh-like directory stack functions and zsh-like hooks. Full use of this file requires a few special UNIX® tools. Note that $ENV must not be set for mksh(1) to parse the ~/.mkshrc file at startup.

Support

We provide an online manual page in HTML and PDF format. Reading books about Korn Shells in general is recommended as further help, but beware of the differences (ATTENTION outdated content behind that link) to other shells. Some ISBNs are listed at the end of the manual page.

The RSS feed collects news and wlog entries regarding mksh.

If you require additional assistance or want to discuss bugs, features or enhancements, write to the mailing list (or subscribe to it). The mailing list can be reached via NNTP or at the MARC web archive (or GMane Loom) as well. Joining the IRC channel at Freenode (irc.freenode.net, SSL port 6697, insecure port 6667) #!/bin/mksh (no joke, this is really the channel’s name) and #ksh (where you must distinguish AT&T ksh from mksh though) is recommended as well.

Installation

Skip to the section about being included in operating environments unless you really want to compile mksh from source yourself or create a package for your operating system of choice.

First off, you have to download the source code from any of the mirrors listed below, or any other mirror you know of. Alternatively, use the development version from CVS. Official source code distributions are a cpio(1) compressed “old-style” (portable octal) archive, compressed with gzip(1) (zlib’s deflate algorithm) and digitally signed with gzsig(1) using the MirOS Project’s current signature key. Please verify the signature as well as the hashes and/or checksums below, so you’re sure the content is intact and the version number on the archive is correct. If you require source code in tar(1)’s “ustar” format, check the Debian Project for availability, although they often do not carry the latest version. The pax(1) utility (the POSIX Archiver) can extract from the CPIO distfile and is available even on a stock Microsoft® Windows® installation (\WINNT\SYSTEM32\PAX.EXE).

Known Mirrors

Checksums and Hashes

Decompression

Use any of the following syntaxes to extract the distfile; you’ll get the idea soon. Some web browsers (prominently, Mozilla® and its derivates as well as Microsoft® Internet Explorer®) already inflate the distfile during download but do not remove the “.gz” extension; replace “gzip -dc” (gzcat) with “cat” if that happens for you.

The first example is using BSD paxtar (MirOS BSD, OpenBSD, NetBSD®), or “bsdtar” (DragonFly); the second and third use cpio(1) or pax(1) and are for most operating systems; the fourth is for Debian.

Patching

If you’re a packager/vendor and need to patch mksh and deviate from the default behaviour for that version which is indicated from $KSH_VERSION, patch your shell to append a space plus a vendor-defined string (examples PLD, Debian) so they can be distinguished. I think this is a reasonable request.

Compilation

Now you’re in the source code directory; Build.sh does all the magic for you. In theory, invoking the command
% /bin/sh ./Build.sh
should work. Relative paths can be used too, for example, instead of cd(1)ing to the source directory, you could’ve done
% mkdir build; cd build; /bin/sh ../mksh/Build.sh

It is optionally possible to place files, such as printf.c, into either the current or the source directory. It will need a compile option (see below) to be activated. printf.c is undesirable because it uses stdio, floating point and bloats.

The build script requires a Bourne shell (Solaris /bin/sh, the Heirloom sh, DEC OSF/1 V2.0 /bin/sh), Korn shell (ksh, ksh88, ksh93, pdksh, mksh, oksh, maybe the MKS ksh), POSIX shell (posh, /usr/xpg4/bin/sh, ash, dash), related shell (yash, J�rg Schilling’s bsh or sh, the Z Shell), or a Bourne or POSIX superset (such as GNU bash) to work; the ULTRIX /bin/sh or the C shell (csh, tcsh) or “bsh” or a scripting shell like the wish won’t.
Accepted arguments are:

Note: “-c somemode”, “-j” and “-M” are mutually exclusive. The least preferred of the actually compiling flavours is -j, and the one we consider best is -c lto (since it achieves the best optimisations). It is sometimes possible to use -j together with -c llvm to parallelise LLVM Bytecode generation, though.

The build script also honours some environment variables detailed at its end.

Operating Environment specific notes

[Minix logo]Compiler: ACK

Support for ACK on Minix 3 has been added in mksh R37c with a workaround a known ACK bug (the “const” bug); it is now perfectly usable.

Support for other ACK versions or targets can be user-contributed. It currently lacks a sane frontend supporting things like “cc -E” (ack -E is ignored), at the least, and does not yet process system headers like <sys/types.h>.

Compiler: Borland C++ Builder

This compiler is somewhat supported in mksh R30 with UWIN’s cc wrapper. (We haven’t been able to produce a working executable though.)

Compiler: DEC/Compaq/HP C for OSF/1 and Tru64

This compiler is fully supported with mksh R33b (partial support did appear earlier).

The ucode based compiler, linker and loader for Digital UNIX (OSF/1) V2.0 on MIPS is supported since mksh R36. It may, however, be forced to link statically to work around a bug in the toolchain.

Compiler: Digital Mars

This compiler is somewhat supported in mksh R30 with UWIN’s cc wrapper and a few kludges. (We haven’t been able to produce a tested executable though, due to general stability issues with the UWIN platform.)

[GCC logo]Compiler: GCC

The GNU C Compiler 1.42, 2.7.2.1, 2.7.2.3, egcs (gcc 2.95) and the GNU Compiler Collection (gcc 3.x, 4.x) are known to work, but not all versions work on all targets. Specific C flags, known extensions, etc. are autoprobed; cross-compilation works fine. Use of gcc 4.x is discouraged because of several dangerous changes in how the optimiser works; it is possible to work around their trading off reliability for benchmark-only speed increases, but because mksh developers do not use gcc 4.x this will have to be user-contributed. On the other hand, gcc 3.x (in some cases 2.x) is the best choice for compiling mksh.

On BSDi BSD/OS, where gcc 1.42 and gcc 2.7.2.1 are available, the cc(1) manual page mentions that gcc 1.42 produces more reliable code, so we recommend to build mksh with CC=cc (gcc1) instead of CC=gcc or CC=gcc2 there instead.

Since mksh uses ProPolice, the Stack-Smashing Protector, some GCC versions’ compilates require additional shared libraries. To disable this, pass HAVE_CAN_FSTACKPROTECTORALL=0 in the build environment.

GCC and Valgrind do not always play well together, hence the build option -valgrind adding -fno-builtin to avoid gcc producing code that can access memory past the end of the allocation.

[HP-UX logo]Compiler: HP C/aC++

HP’s C compiler (/usr/bin/cc on HP-UX) is supported in mksh R30 and above; on IA64, only the LP64 model can be used; mksh used to segfault in the ILP32 module (or rather, the system libraries did, I think), so it was default. PA-RISC too works fine, so this compiler is a primary choice.

In mksh R39b and up, you must set CFLAGS='+O2 +DD64' on IA64 to get the same behaviour as previous versions; the 32-bit mode is now the default. The HP-UX bundled compiler /usr/ccs/bin/cc works as well as HP aCC, except of course that it does not optimise. (GCC and C99 extensions aren’t actually used by mksh.)

Compiler: IBM XL C/C++ / VisualAge

IBM xlC 9.0 on AIX 5.3 is supported in mksh R30 and above.

IBM xlC 8.0 on Linux/POWER and IBM xlC 6.0β on MacOS X are on the TODO.

IBM xlC 7.0 on AIX 5.2 is supported in mksh R35c and above.

Compiler: Intel C/C++/Fortran

ICC emulates GCC quite well (too well for my taste), is fully supported in mksh R30 and above on several platforms, but spits out lots (and I mean huge ugly lots) of bogus warnings during compile. We’re not going to work around these; let Intel fix their compiler instead. Some of these warnings were even responsible for bugs in mksh.

I could not get the Intel Compiler 10 for Windows® to work.

mksh enables the ICC stack protector option automaticaly. Compilates usually require the Intel shared libraries to be around.

[LLVM logo]Compiler: LLVM

Apple llvm-gcc from Xcode 3.1 had full success with mksh R34.

Vanilla llvm-gcc works fine as well.

Vanilla llvm-clang starting at r58935 produces working code with mksh R36b and up.

Compiler: Microsoft® C/C++

Support for the Microsoft® C Compiler on Interix and UWIN, with the respective /usr/bin/cc wrappers, appeared in mksh R30. The following product versions have been tested:

CL.EXE: Microsoft (R) 32-bit C/C++ Standard Compiler Version 13.00.9466 for 80x86
LINK.EXE: Microsoft (R) Incremental Linker Version 7.00.9466

(both are part of the .NET Common Language Runtime redistributable)

CL.EXE: Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.42 for 80x86
LINK.EXE: Microsoft (R) Incremental Linker Version 8.00.50727.42

(both are part of Visual Studio 2005 C++ Expreß)
You’ll have to change Interix’ cc(1) wrapper though: replace /Op with /Gs- to disable the stack checks (missing support in libc for them, they used to be off by default) and remove /Ze.

On Interix (SFU 3.5), this compiler is maturely usable and a good choice.

On GNU/Cygwin, using wgcc it might be possible to use this compiler. I could not test that yet, though.

On UWIN, this is usable as well.

Compiler: MIPSpro

Support for SGI’s MIPSpro compiler on IRIX appeared in mksh R33b.

[nwcc logo]Compiler: nwcc

Support for nwcc appeared in mksh R36b; it is recommended to use nwcc 0.8.1 with mksh R39c or newer. The stack protector is currently disabled because it introduces errors.

Compiler: PCC (BSD)

Support for the Caldera/SCO UNIX® based, BSD-licenced portable C compiler in the ragge version has been added with mksh R31d. Versions from end of April 2008 onwards are known to work reliably, even with -O enabled.

Compiler: SUNpro

Support for the SUN Studio 12 compiler (cc 5.9) as well as cc 5.8 appeared in mksh R30; other versions might be supported as well. This compiler is a primary choice.

Using SUNWcc on MirBSD/i386

Preparation steps. We assume that Sun Studio is extracted under the /opt/SUNWcc directory and Linux emulation has been set up. From now on, $S is /opt/SUNWcc/sunstudio12.1 (when using an older version, no “.1” at the end).

$ cat $S/../MirBSD/ld                   # must be executable (0555)
#!/bin/mksh
set -A args -- "$@"
integer i=0
while (( i < ${#args[*]} )); do
        [[ ${args[i]} = -dynamic-linker ]] && args[i+1]=/usr/libexec/ld.so
        [[ ${args[i]} = -Y ]] && args[i+1]=/usr/lib
        let ++i
done
exec /usr/bin/ld "${args[@]}"

In $S/prod/include “mkdir MirBSD_orig” and “mv cc MirBSD_orig/”. In $S/prod/lib “mkdir MirBSD_orig” and “mv *.o MirBSD_orig/” then “mv MirBSD_orig/values-xa.o .” (we need this one).

Furthermore, run “make obj && make depend && make && make sunstuff” in /usr/src/lib/csu/i386_elf then copy the three files obj/sun_crt{1,i,n}.o to $S/prod/lib/crt{1,i,n}.o (they are the MirBSD glue code / startup files).

For some versions, you may need to ensure /emul/linux/lib and /emul/linux/usr/lib do not contain any *.so or *.o files, except for libbfd, libopcodes, libstdc++ (but 12.1 uses the native linker).

In 12, -xO2 is broken; in 12.1 optimisation merely lets ir2hf run out of memory even with ulimit -d ulimit -dS 1572864, hence, -xipo cannot be used either. ☹

Using SUNWcc on MirBSD to build mksh

 $ S=/opt/SUNWcc/sunstudio12.1
 $ LD_LIBRARY_PATH=$S/prod/lib/sys:$S/prod/lib:$S/rtlibs CC=$S/prod/bin/cc \
   LDFLAGS="-Yl,$S/../MirBSD" mksh /usr/src/bin/mksh/Build.sh -r
[tcc logo]Compiler: tcc (Tiny C)

Support for Fabrice Bellard’s tcc appeared in mksh R31, although its unability to do ‘-E’ in older versions gave us some headache. The bounds checker is currently disabled as it causes segfaults.

Compiler: TenDRA (maybe Ten15 too)

Support for TenDRA appeared in mksh R31 and appears to be solid; mksh uses the ‘system’ profile for compiling by default. Users who wish to build mksh with a different profile are welcome to help to port it.

See ULTRIX for an example of getting a ‘POSIX’ profile to work.

Compiler: DEC ucode (MIPS CC)

Since mksh R33c, ucode on Ultrix is fully supported.

[FreeWRT logo]Distribution: FreeWRT, OpenADK, OpenWrt

These distributions provide the same support cross-platform, with µClibc and/or eglibc, and thus should behave the same on all supported targets.

Platform: Android

Supported with OpenADK (static eglibc) and NDK (although the build process is currently not feasible with an Android.mk file but possible if the CPPFLAGS and signames.inc are pregenerated; sys_signame[] has been pushed upstream and is in Android 1.6). Integration into both AOSP and the Google master, as /system/bin/sh, has been done and it can be enabled on a per-target basis at the moment; mksh is shipped with Android 3.0 and newer releases.

Platform: iPhone

This is just Mac OSX, compile (natively, or cross via the SDK) and copy.

Platform: Maemo

This is like Debian, and packaging is available via the Garage and the Extras repository. Helpers (for GUI integration and actual on device testing) seeked.

Toolchain: dietlibc

Fefe’s dietlibc works in mksh R34, although his opinion towards certain standards, such as caddr_t, strcasecmp(3), etc. are weird.

Toolchain: klibc

klibc needs -DMKSH_NO_LIMITS and can then use stock klcc as compiler wrapper (CC=klcc). Then, mkstemp(3) must be added to klibc, and we’re hunting down a signal delivery problem (currently, with -DMKSH_NOPROSPECTOFWORK it works).

Toolchain: musl

Has broken -D_GNU_SOURCE, needs -D_BSD_SOURCE too, so figure out a new set of forced CPPFLAGS for this. Compiler wrapper is broken with many gcc versions. Signals are broken but with -DMKSH_NOPROSPECTOFWORK it works.

OS: AIX

Support for AIX with xlC appeared in mksh R30.

[Haiku logo]OS: BeOS / Haiku

ahoka@ had begun porting. mksh R39c has been tested on 2010-03-13; a kernel from r35836 up is required due to a bugfix wrt. signal handling. (This for Haiku; we have no idea about BeOS.)

gcc4hybrid might not work, gcc2hybrid might work well.

OS: BSDi BSD/OS

BSD/OS 3.1 works fine with mksh R33.

OS: MS-DOS, DR DOS, FreeDOS

DJGPP’s bash.exe fails to run Build.sh, thus this is currently not supported. (We tried!)

[Cygwin logo]OS: GNU/Cygwin

This operating environment is supported as much as it adheres to standard POSIX/SUSv3 conformant things. No workarounds for .exe suffixes or other platform-specific quirks have been or will be added.

OS: Darwin / Mac OSX

Works pretty well.

[DragonFly logo]OS: DragonFly BSD

Perfect choice. Note /bin/sh compatibility needs a quirk.

[FreeBSD logo]OS: FreeBSD

Perfect choice. Note /bin/sh compatibility needs a quirk.

[Hurd logo]OS: GNU/Hurd

This operating system is supported (on i386) since R29 but not well tested. mksh is part of Debian GNU/Hurd, so it is expected to work.

Starting with mksh R39b, there is no arbitrary limit on pathnames any more, as the operating system requires. (However, there are still other inherent limits in mksh, such as that of an interactive input line.)

[Debian GNU/kFreeBSD logo]OS: GNU/k*BSD

This operating environment has been supported for quite a while as part of Debian and somewhat tested.

[Linux logo]OS: GNU/Linux

While POSIX does not apply to “GNU’s Not Unix”, the FHS (ex-FSSTND) does; please convince your distributor to move ed to /bin/ed if not already done. Manual page installation paths are not standardised in older distributions either.

Besides glibc (GNU libc), dietlibc (from Fefe), µClibc (embedded), klibc (for initramfs) and libc5 (on Linux 2.0.38) work, but locale detection is not automatic for some of them.

mksh can be used as /bin/sh on Debian and similarly strict distributions, which allow to use e.g. ash/dash there as well.

[HP-UX logo]OS: HP-UX

Support for HP-UX with GCC appeared in mksh R29 and works with HP’s C compiler and is no longer experimental in mksh R30. Please use stty(1) to make the terminal sanely usable.

If passing custom CFLAGS, don’t forget -mlp64 (GCC) or +DD64 on Itanium.

OS: Interix

We have only tested SFU 3.5 on Windows® 2000, not SUA on Windows® 2003 SR1 or the version integrated into Vista. Windows 7’s works, gcc only though.

As the Unix Perl which comes with Interix is too old, and the ActiveState Perl has… other issues, to run the regression tests, please install Perl from NetBSD® pkgsrc® instead.

As of mksh R30, the native compiler (cc(1)) is supported in addition to gcc, calling Microsoft C. Do not use the c89(1) wrapper.

If passing custom LIBS, don’t forget to add -lcrypt or any other library providing arc4random(3).

mksh can replace /bin/ksh and /bin/sh without any problems.

OS: IRIX

Support for IRIX64 6.5 appeared in mksh R33b.

[MidnightBSD logo]OS: MidnightBSD

mksh is part of MidnightBSD 0.2-CURRENT and above and used as native /bin/ksh; it can be used as /bin/sh as well with a quirk.

MidnightBSD 0.3 uses mksh as /bin/sh indeed.

[Minix logo]OS: Minix

Minix 3 is supported starting mksh R37b (gcc), R37c (ACK/adk cc). Minix 1 and Minix 2 will never be supported due to size constraints on 16-bit platforms, unless a user contributes code.

OS: MiNT / FreeMiNT

Support appeared in mksh R40. Depending on the distribution you use, you must use pdksh with CC=gcc to run Build.sh – cc and bash are both too broken. Afterwards, you must use the just-built mksh (after moving it out of the build directory) to re-run Build.sh with the same flags, due to bugs in pdksh on MiNT as well.

Most things work. FD_CLOEXEC is broken, so filedescriptor privacy has POSIX level only. /dev/tty is usually unusable; it might help to symlink /dev/console there but break other things.

(At OpenRheinRuhr 2011, tg@ had access to a FreeMiNT distribution which did not seem to exhibit any of the mentioned problems. YMMV.)

[MirBSD logo]OS: MirBSD

Perfect choice. This is where mksh comes from.

[NetBSD logo]OS: NetBSD

Perfect choice.

Starting with NetBSD 1.6, mksh can replace /bin/ksh and /bin/sh without any problems. On NetBSD 1.5, mksh can only replace /bin/ksh safely.

OS: MSYS

mksh compiles on MSYS (that is something different from using MinGW for the nascent native WinAPI port; it’s basically an old version of Cygwin wrapped) with few issues.

[OpenBSD logo]OS: OpenBSD

The setlocale(3) call in OpenBSD’s libc will always return the “C” locale and therefore has been disabled by default.

mksh can replace /bin/ksh and /bin/sh without any problems. mksh is supposed to be a superset of oksh (except GNU bash-style PS1, weird POSuX character classes, and an incompatible ulimit builtin change).

OS: DEC/Compaq OSF/1, Compaq/HP Tru64

Digital Unix is somewhat supported using gcc as of mksh R31b. With mksh R33b, many more versions and the native compiler work. In fact, gcc sometimes segfaults, so use the vendor compiler.

[Plan 9 mascot]OS: Plan 9

Needs retesting with mksh R40+ (port unfinished)

Plan 9 is not supported yet – we were able to create an executable, but it did not return to the prompt after running a non-builtin command; this is job control issues, and patches are welcome. (Note this is for R37 and below; R37b might actually work, but someone would have to test this.)

Due to the unavailability of ttys, job control will never be supported. With -DMKSH_NOPROSPECTOFWORK it will probably work.

The APE (ANSI’n’POSIX Environment) is required to build mksh; I don’t remember which compiler I used, but I think it was GCC.

OS: PW32 on Win2k

PW32 is not supported yet – killpg(3) is missing, and it’s possible that PW32 and Minix 3, at least, need job control disabled or worked around. Maybe peek at how ash/bash for PW32 do it. gcc works.

OS: QNX/Neutrino

QNX/Neutrino (Perl: “nto”) support appeared in mksh R36b.

The QNX ed(1) used to fail the regression tests due to being broken; compile the MirBSD ed and place it in /bin/ to fix this, or get an updated ed from vendor.

[OpenSolaris logo]OS: Solaris

Solaris is full supported since “forever” with gcc, and since mksh R30 with Sun’s C compiler. Both 32-bit and 64-bit modes work; 64-bit mode is not enabled by default by Build.sh, you must do that manually by passing CFLAGS of -O2 -m64 or -xO2 -xarch=generic64.

Solaris does not come with Berkeley mdoc macros for nroff, so using the HTML or PDF versions of the manual pages or pregenerating a catman page on another OS is required.

[Syllable logo]OS: Syllable Desktop

Needs retesting with mksh R40+ (port unfinished)

This does not yet work due to a signal passing bug in the AtheOS kernel, we were told by their developers. However, mksh R33 is at the same level of support as Plan 9 now.

Chances are a more recent mksh works with a more recent Syllable. With -DMKSH_NOPROSPECTOFWORK it will probably work.

Syllable Server will work, as it is, at the moment, “just” a GNU/Linux distribution with a different GUI. This may change though.

OS: ULTRIX

Even on ULTRIX 4.5, mksh R33c works fine. The system ksh must be used for running the Build.sh script, though.

I could not get networking on ULTRIX 4.0 (SIMH) to work, so I could not test it there.

You however must pass the -YPOSIX option to the ucode compiler, as the default -YBSD profile produces a broken executable (spins instead of starting up), and the -YSYSTEM_FIVE profile does not even compile. See TenDRA for another OE which has issues with different OE profiles. (Build.sh takes care of this automatically.)

OS: UWIN-NT

Compilation of mksh R30 on UWIN works with several compilers (bcc, dmc, msc – I could not get gcc-egcs, gcc-2.95, gcc-mingw, icc to work) but the platform itself is very flakey, and even some regression tests crash, due to target limitations apparently. Within these limits, mksh is usable.

OS: Windows

Michael Langguth, partially under work sponsored by his employer Scalaris AG, is currently working on porting mksh to native Win32 (WinAPI) to complete the GNU utilities for Win32 with a native shell to have a free interoperability solution for scripting. Progress is promising, but still a long way to go. The result will probably not be part of mksh itself, but a separate product; some core patches will however end up in core mksh.

After compiling

The Build.sh script generates an executable (“mksh”, except on GNU/Cygwin, where it is called “mksh.exe”), a shell script to use the newly built mksh to run the regression test suite (“test.sh”), and (unless the -r option was given) a pre-formatted manual page (“mksh.cat1”). It also lists installation instructions unless -Q was provided. Now it’s the time to run
% ./test.sh -v -f
in order to see if the shell works. The regression testsuite will exit with errorlevel 1 if any tests failed that are not marked as allowed to fail (e.g. OS dependent) or expected to fail, 0 otherwise. Omit the ‘-f’ option if you do not have a fast (say 1½ GHz Pentium-M) machine.

The regression tests need a controlling tty. Please ensure you have one, even for bulk/dæmonised builds; you can use GNU screen or script(1) to provide one by running the testsuite inside it (see the Debian and OpenSuSE Buildservive packaging for examples of how to do it). If, however, you absolutely cannot get the necessary utilities and devices installed in the build chroot, run: ./test.sh -v -C regress:no-ctty

To actually install mksh, copy the binary to some place in $PATH, i.e. /bin/mksh, $HOME/.bin/mksh, /usr/local/bin/mksh, or whatever your packaging system wants; strip it and run chmod 555 on it. (This can easily be achieved with install(1) – on Solaris, this is /usr/ucb/install not /usr/bin/install – with the arguments -c, -s, -m 755¹, and -o/-g. ① with 555, strip(1) cannot write the file any more, chmod 555 afterwards.) Also append its installation path to /etc/shells, install the dot.mkshrc file (usually alongside with the copyright file and other documentation), copy it to /etc/skel/.mkshrc if your operating environment has this means to include default dotfiles; install either the catman page (mksh.cat1) to, for example, /usr/share/man/cat1/mksh.0, or the mdoc page (mksh.1) to the standard location (/usr/share/man/man1/ or /usr/man/man1/ or whatever your operating environment requires). The manual page requires the Berkeley mdoc macros (either the BSD or the GNU groff version) to be installed during formatting time.

Note that a ~/.mkshrc file will not be executed if $ENV is set and not empty, nor is there an /etc/mkshrc.

For packagers: Upgrades

Note: This is not the ChangeLog, these are the packager-visible upgrade notes regarding changes in the build system (Build.sh and friends, compiler support, packaging conventions, bad examples, etc). This is also not the users' upgrade caveat list.
Packagers also please note: it’s mksh or “The MirBSD Korn Shell” (“MidnightBSD Korn Shell” is also appropriate), but never Mksh or somesuch!

mksh R40d has several new options: test.sh ‘-f’ to enable running tests that need a fast machine; the preprocessor flag MKSH_DISABLE_DEPRECATED to disable code that is deprecated and scheduled for removal in the next version; updated dot.mkshrc.

mksh R40c got better support for OPENSTEP, Interix, kFreeBSD, MSYS, Hurd. No packaging changes worth mentioning, though.

mksh R40b changed dot.mkshrc and has a new option for disabling special handling the cat(1) builtin. The system and suid profile have moved to /system/etc/ for Android. Build failures (e.g. broken system includes abusing inline vs. broken GCC --combine) may now be caught earlier, so Rebuild.sh may not be available yet.

mksh R40 has substantially changed Build.sh options, CPPFLAGS, etc. and the testsuite now exits with an error code if tests fail. Please do review your packaging; contact us if necessary. Specifically for embedded systems (do not do this on desktops etc.), the ~/.mkshrc location can be changed at compile time. Several more operating systems are supported. setmode.c is gone and HAVE_MKNOD defaults to 0 now but can be explicitly enabled, provided your OS has setmode(3) and getmode(3), or it is provided in $LIBS. arc4random.c is no longer used, unless specifically called for by -DMKSH_A4PB (e.g. on Cygwin). Upgrade printf.c to the latest version if you use it. First release to officially support Android; quell aliasing “stop” and “suspend” there. MKSH_SMALL doesn’t imply HAVE_REVOKE=0 any longer.

older entries

Download the development version via CVS

You can use cvs(GNU) to download the development version of mksh(1), commonly called HEAD (or “trunk” to some). Beware of bugs though we strive to make it installable (at least on MirBSD ☺) at all times.

% env CVS_RSH=ssh cvs -qd _anoncvs@anoncvs.mirbsd.org:/cvs co -PA mksh

You might also want to get the printf.c builtin, but this is optional, strongly discouraged and use it only if you really must:

% env CVS_RSH=ssh cvs -qd _anoncvs@anoncvs.mirbsd.org:/cvs co src/usr.bin/printf

Installation instructions as above, although the Build.sh options, CPPFLAGS, etc. might have changed a little in the meantime. In general, you want the following:

% cd mksh
% sh Build.sh -r -c lto

Optionally set CC and other variables, as usual.

Inclusion in other operating systems

These packages are not official and have not always been tested by mksh developers; please keep this in mind.

Users' Upgrade Caveat

This does not necessarily list new features, only these which users should be aware of for existing scripts.

R40d: Interpreting "010" as octal number is now deprecated and will be removed soon. You can now use “local” and “set -A” together to create function-local arrays. The test(1) built-in command behaves POSIX conformant. The ^O Emacs mode command now works as it used to when editing the fetched lines. Arithmetic expressions have certain guarantees that are detailed more explicitly in the manpage.

R40c: The hack for when an interactive command begins with ‘!’ to substitute that with “fc -e -” is now deprecated and will be removed with R41 (or R42, we’ll see) despite objection. Write ‘r ’ (letter err plus a space) instead, it’s exactly the same. On the other hand, GNU bash-style array assignments are now a standard feature: x=(a [3]=b); x+=(c [6]=d) now works even in -DMKSH_SMALL. The -DMKSH_BINSHREDUCED fix for ${foo%\?} needed another fix, same for the recursive parser introduced in R40.

R40b: There is a new built-in special command “global” which does the same as “local” except localise every parameter it touches; in short, it does what “typeset” would’ve been supposed to be had it not to double as “local”. Tab completion will now work better. The shell handles bogus environment variable imports more gracefully and doesn’t let the terminal crash hard under some corner cases. ^Cing out of the built-in cat utility is possible.

R40: “set ±o arc4random” is deprecated and will not exist in the next version (R41) any more – the shell uses an LCG internally which is seeded from ASLR. Several POSIX fixes may change behaviour of builtins, substitutions, etc. and some differ now depending on the “set ±o sh” flag. New builtin “cat” (although, if called with a flag, the external cat utility is invoked) and “sleep” (if select(2) could be linked). dot.mkshrc no longer exports $PS1. GNU bash localised strings ($"…") are handled, but (of course❣) untranslated. “foo=<<EOF” cat(1)lessly assigns a here document to a parameter. New KSHEGID, KSHGID, KSHUID variables and PIPESTATUS array. Completely new read built-in command with several new options. Parse command substitutions – $(…) – recursively. HP-UX “test -H” is back, “test -t” (without the “fd” argument) is gone. “set -x” is now inherited by called functions. The x+=y and x+=(y z) notations for appending to variables and (!MKSH_SMALL) arrays are now supported, as are “;&” and “;|” (“;&&” !MKSH_SMALL too) case fall-through without/with re-examination.

older entries

Recent Changes

Changes in the current (unreleased) development version:

Changes in the current (unreleased) stable branch:

mksh R40d is a must-have bugfix update:

mksh R40c collects stable development, mostly fixes:

mksh R40b introduces several desired fixes:

mksh R40 is a major everything release:

older changes

Future Plans

MirOS Logo