---
name: "lksh"
section: "1"
platform: "linux"
package: "mksh"
version: "59c-41+b2"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/lksh"
---

# lksh(1)

Legacy Korn shell built on mksh

## NAME

**lksh** – Legacy Korn shell built on mksh

## SYNOPSIS

**lksh** \[**N+abCefhiklmnprUuvXx**\] \[**N+o** *opt*\]\[ **Nc** *string* **Ns** *file* \[*args* *...*\]\]

## DESCRIPTION

**lksh** is a command interpreter intended exclusively for running legacy shell scripts. It is built on **mksh**; refer to its manual page for details on the scripting language. It is recommended to port scripts to **mksh** instead of relying on legacy or objectionable POSIXNmandated behaviour, since the MirBSD Korn Shell scripting language is much more consistent.

Do not use **lksh** as an interactive or login shell; use **mksh** instead.

Note that it4s strongly recommended to invoke **lksh** with **No** **posix** to fully enjoy better compatibility to the POSIX standard (which is probably why you use **lksh** over **mksh** in the first place); **No** **sh** (possibly additionally to the above) may be needed for some legacy scripts.

## LEGACY MODE

**lksh** currently has the following differences from **mksh**:

- The KSH\_VERSION string identifies **lksh** as “LEGACY KSH” instead of “MIRBSD KSH”. Note that the rest of the version string is identical between the two shell flavours, and the behaviour and differences can change between versions; see the accompanying manual page [mksh(1)](/mksh/1.md) for the versions this document applies to.

- **lksh** uses POSIX arithmetic, which has quite a few implications: The data type for arithmetic operations is the host ISO C *long* data type. Signed integer wraparound is Undefined Behaviour; this means that...

  ```
  $ echo $((2147483647 + 1))
  ```

  ... is permitted to, e.g. delete all files on your system (the figure differs for nonN32Nbit systems, the rule doesn4t). The sign of the result of a modulo operation with at least one negative operand is unspecified. Shift operations on negative numbers are unspecified. Division of the largest negative number by N1 is Undefined Behaviour. The compiler is permitted to delete all data and crash the system if Undefined Behaviour occurs (see above for an example).

- The rotation arithmetic operators are not available.

- The shift arithmetic operators take all bits of the second operand into account; if they exceed permitted precision, the result is unspecified.

- Unless **set** **No** **posix** is active, **lksh** always uses traditional mode for constructs like:

  ```
  $ set NN $(getopt ab:c "$@")
  $ echo $?
  ```

  POSIX mandates this to show 0, but traditional mode passes through the errorlevel from the [getopt(1)](/getopt/1.md) command.

- Functions defined with the **function** reserved word share the shell options (**set** **No**) instead of locally scoping them.

## SEE ALSO

[mksh(1)](/mksh/1.md)

*http://www.mirbsd.org/mksh.htm*

*http://www.mirbsd.org/kshNchan.htm*

## CAVEATS

To use **lksh** as */bin/sh*, compilation to enable **set** **No** **posix** by default if called as **sh** (adding NDMKSH\_BINSHPOSIX to CPPFLAGS) is highly recommended for better standards compliance.

For better compatibility with legacy scripts, such as many Debian maintainer scripts, Upstart and SYSV init scripts, and other unfixed scripts, also adding the NDMKSH\_BINSHREDUCED compileNtime option to enable *both* **set** **No** **posix** **No** **sh** when the shell is run as **sh**, as well as integrating the optional disrecommended [printf(1)](/printf/1.md) builtin, might be necessary.

**lksh** tries to make a cross between a legacy bourne/posix compatiblNish shell and a legacy pdkshNalike but “legacy” is not exactly specified.

Talk to the MirBSD development team and users in the #!/bin/mksh IRC channel; mind the infos from *http://www.mirbsd.org/mkshNfaq.htm#contact* for either. Consider migrating your legacy scripts to work with **mksh** instead of requiring **lksh**.
