The MirBSD Korn Shell

Sponsored by
HostEurope Logo

The MirBSD Korn Shell

⚠ This page contains old, outdated, obsolete, … historic or WIP content! No warranties e.g. for correctness!

mksh — specific notes for operating environments

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: C68 (C386, etc.)

The Walkers’ C89 compiler is not supported at the moment, but this is mostly due to difficulties in figuring it out. Any people who actually got it to compile anything, especially for both Linux and Minix, for both i386 and m68k, please contact us.

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,,, 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. Early 2.x versions (like 2.1) may make trouble. 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 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.)

Note: on old HP-UX (e.g. 9), use c89, not cc.

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.

IBM xlC 5.0 on AIX 5.1L also works.

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 automatically. Compilates usually require the Intel shared libraries to be around.

Compiler: libFirm/cparse

libFirm with the cparse front-end is indistinguishable from GCC and known to build mksh R41 just fine.

[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. Intermediate bugs that may have appeared are just as quickly fixed.

Compiler: Quick C — cc(CP)

This is the Microsoft-based vendor compiler on older SCO OpenServer, recognised from mksh R60 on. Newer versions use USL C.

Compiler: SmallerC

A port of mksh to SmallerC (smlrc) was begun, but removed because the developer of that compiler refused to even discuss working on it.

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.

Sun Forte Developer 7 C 5.4 2002/03/09 also works.

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)
set -A args -- "$@"
integer i=0
while (( i < ${#args[*]} )); do
        [[ ${args[i]} = -dynamic-linker ]] && args[i+1]=/usr/libexec/
        [[ ${args[i]} = -Y ]] && args[i+1]=/usr/lib
        let ++i
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/ -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. Some intermediate versions of tcc break every once in a while.

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.

Compiler: USL C

This is the vendor compiler on recent SCO OpenServer and SCO UnixWare. It is recognised from R40f onwards. (Older SCO OpenServer uses Quick C, based on the Microsoft compiler.)

Distribution: OpenADK

This development kit provide the same support cross-platform, with µClibc, musl and/or glibc, and thus should behave the same on all supported targets.

Distribution: OpenWrt

This distribution provides the same support cross-platform, with µClibc and/or glibc, and thus should behave the same on all supported targets.

Platform: Android

Supported with OpenADK (static) and NDK (although the build process is currently not feasible with an file but possible if the CPPFLAGS and 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 and the standard shell of non-emulator builds on Android 4.0 and newer.

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

Toolchain: musl

musl < 1.1.11 has a "C" locale so broken it cannot be used with a shell with locale tracking. RUN THE TESTSUITE! Either upgrade to a newer version of musl or disable setlocale(3) calls and have mksh use the fallback of directly looking at the LANG/LC_* variables by exporting HAVE_POSIX_UTF8_LOCALE=0 before running (and possibly adding -DMKSH_DEFAULT_UTFLOC to CPPFLAGS to match defaulting to UTF-8, not 7-bit ASCII, if the LANG/LC_* parameters are unset or empty; this may or may not be in your interest, depending on what to match; musl certainly knows “only” UTF-8).

Otherwise, this appears to work just fine in R41b and up.

OS: 386BSD

This seems to work with mksh R41, although on 386BSD-0.0new (anything older than 386BSD-0.1) you need to patch the kernel against a close-on-exec bug and a bug when switching the terminal between cooked and raw mode as well add an execve with support for shebangs and long command liness.


Support for AIX with xlC appeared in mksh R30.

[A/UX logo]OS: A/UX

mksh R59c and up work on A/UX, but currently can only be compiled with GCC, not the system compiler (although the reader is invited to fix that). Make sure to install all updates and bugfixes for the OS.


BeOS can, with limitations, be used with R40f and up. Job control is not working, and mksh must be rebuilt (once built) by running with the same options again but using the just-built mksh as interpreter due to a severe pipe-related bug in the system sh. RT supplied a port to BeOS 6.2 “Zeta” and managed to make the shell somewhat work on 5.1 “Dano” and 5.0 “Maui”.


BSD/OS 3.1 works fine with mksh R33.

OS: Coherent

This is a somewhat experimental port in mksh R41. (More information will follow.) Set TARGET_OS=Coherent manually.

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

OS: Dell UNIX 4.0 R2.2 (SVR4)

This exot has been tested with R40f: gcc is absolutely unusable on this platform but the vendor compiler works.
Set TARGET_OS=_svr4 manually.


This environment lacks fork(2) and other required functionality to support a Korn-ish shell. To add insult to injury, for a long time, DJGPP’s bash.exe failed to run (We tried!)

[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 using e.g. ash/dash there as well.

[Haiku logo]OS: Haiku

Haiku can be used with mksh R39c and newer with a recent kernel from r35836 and newer, ca. mid-2010 due to a bugfix wrt. signal handling. gcc4hybrid might not work, gcc2hybrid might work 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.


Support for IRIX64 6.5 appeared in mksh R33b.

OS: Jehanne

A Plan 9 derivative with much improved support for the POSIX runtime environment, can run mksh R56c and newer. Still work in progress, both the operating system itself and the mksh port, but usable by now.

OS: LynxOS

Although the promised evaluation version never arrived, someone managed to test mksh R40f on LynxOS 3. RT is improving the port.

[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 3

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. You will need:

# chmem =1048576 /usr/lib/em_cemcom.ansi
# chmem =262144 /usr/lib/i386/as

Append the following line to main.c on Minix 3.1.2a or older:

void _longjmp(jmp_buf env, int val) { longjmp(env, val); }
OS: Ninix 3

Ninix 3 (Minix 3 with NetBSD® code) has first been working starting with mksh R40e (clang). More porting and tests are needed. This is different from “regular” Minix 3. Do be sure to set your TARGET_OS environment variable correctly.

OS: Minix-386

mksh R42 works on Minix-386 down to version 1.7.0 but not 1.5 due to OS limitations; you might have to compile on version 2.0 as the ACK bundled with 1.7 segfaults.

OS: Minix-vmd

mksh R42 works fine on Minix-vmd 1.7 with ACK.

OS: Minoca OS

RT contributed a well-working port to this operating system.

OS: MiNT / FreeMiNT

Support appeared in mksh R40. Depending on the distribution you use, you must use pdksh with CC=gcc to run — 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 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.


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.

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

Except for OpenStep 4.2 which has a completely botched POSIX library (although rumours are there is a libposix.a in existence that can be copied onto it), it works with R40f onwards. (Binaries of NeXTstep 3.3 can be copied onto OpenStep 4.2 and used there.) You need gawk.

[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/2 logo]OS: OS/2

mksh has been ported to OS/2 with kLIBC. The -T option to enables “TEXTMODE”, which supports reading CR+LF line endings but breaks compatibility with Unix mksh.

OS: z/OS (OS/390)

mksh is currently undergoing porting to EBCDIC but should already work in an ASCII environment using xlC. z/Linux has less bugs than the USS environment though.

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

Plan 9 is not supported yet. Due to the unavailability of ttys, full job control will never be supported. Input line editing likewise cannot work in drawterm. Currently, a kernel or APE bug requires the use of -DMKSH_NOPROSPECTOFWORK but this doesn’t produce a fully working mksh (some features cause the shell to hang).

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. Jens Staal reports success with kencc though, so I’d suggest using that instead.

OS: PW32 on Win2k

PW32 is not supported yet — killpg(3) is missing, and it’s possible that PW32 needs job control disabled or worked around, since a workable binary can be made with -DMKSH_NOPROSPECTOFWORK (note that this option produces a shell not supporting standard Korn Shell scripts). 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.

04:02 < kiwichris> Just dropped by to say I built mksh for RTEMS
                   ( and can run it on a
                   sparc simulator.
04:02 < xiaomiao> nice!
04:03 < kiwichris> yeah it is; cannot do to much at the moment because
                   rtems is a statically linked binary and
                   commands are 'functions'
OS: SCO OpenServer, SCO UnixWare

SCO OpenServer 3.2r4.2 and 5 lack job support, which SCO OpenServer 6 and SCO UnixWare 7.1.1 appear to have working. The shell works.

OS: SerenityOS

RT managed to build mksh on SerenityOS whose developers are actively adding necessary functionality, so make sure to use the latest. The testsuite currently cannot yet be run.


RT managed to build mksh on SkyOS. It somewhat works, and the testsuite failures are probably all bugs in their POSIX layer.

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


On mksh R42, add -DMKSH_TYPEDEF_SIG_ATOMIC_T=int and -DMKSH_TYPEDEF_SSIZE_T=int in addition to -DMKSH_UNEMPLOYED -DUSE_REALLOC_MALLOC=0 and SunOS 4.1.1 with GCC will work.

[Syllable logo]OS: Syllable Desktop

This OE is suffering from bugs in older versions (with -DMKSH_NOPROSPECTOFWORK these worked a bit better but disabling jobs completely with that option produces a shell not supporting standard Korn Shell scripts.)

Newer versions seem to work; fd-cloexec-{1,2} tests fail but fd-cloexec-3 passes so its perl (or something) might be the cause for the failure.

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


Even on ULTRIX 4.5, mksh R33c works fine. The system ksh must be used for running the 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. ( takes care of this automatically.)


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.

A beta version of this is available as announced in this wlog entry.

OS: Xenix

Thanks to RT, cross-build to SCO Xenix 386 2.3.4a TARGET_OS=XENIX from SCO OpenServer 3.2r4.2 with CFLAGS="-x2.3" LIBS="-l2.3 -ldir" works. Native build will require more porting… this is ancient! ☻☺

Inclusion in other operating systems

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

MirBSD Logo