-.\" $MirOS: src/bin/mksh/lksh.1,v 1.10 2015/04/12 22:32:12 tg Exp $
+.\" $MirOS: src/bin/mksh/lksh.1,v 1.23 2017/04/02 13:38:02 tg Exp $
.\"-
-.\" Copyright (c) 2008, 2009, 2010, 2012, 2013, 2015
-.\" Thorsten “mirabilos” Glaser <tg@mirbsd.org>
+.\" Copyright (c) 2008, 2009, 2010, 2012, 2013, 2015, 2016, 2017
+.\" mirabilos <m@mirbsd.org>
.\"
.\" Provided that these terms and disclaimer and all copyright notices
.\" are retained or reproduced in an accompanying document, permission
.\" * ^ is size-reduced and placed atop in groff, so use \*(ha
.\" * \(en does not work in nroff, so use \*(en
.\" * <>| are problematic, so redefine and use \*(Lt\*(Gt\*(Ba
-.\" Also make sure to use \& especially with two-letter words.
+.\" Also make sure to use \& *before* a punctuation char that is to not
+.\" be interpreted as punctuation, and especially with two-letter words
+.\" but also (after) a period that does not end a sentence (“e.g.\&”).
.\" The section after the "doc" macropackage has been loaded contains
.\" additional code to convene between the UCB mdoc macropackage (and
.\" its variant as BSD mdoc in groff) and the GNU mdoc macropackage.
.\" with -mandoc, it might implement .Mx itself, but we want to
.\" use our own definition. And .Dd must come *first*, always.
.\"
-.Dd $Mdocdate: April 12 2015 $
+.Dd $Mdocdate: April 2 2017 $
.\"
.\" Check which macro package we use, and do other -mdoc setup.
.\"
refer to its manual page for details on the scripting language.
It is recommended to port scripts to
.Nm mksh
-instead of relying on legacy or idiotic POSIX-mandated behaviour,
+instead of relying on legacy or objectionable POSIX-mandated behaviour,
since the MirBSD Korn Shell scripting language is much more consistent.
+.Pp
+Do not use
+.Nm
+as an interactive or login shell; use
+.Nm mksh
+instead.
+.Pp
+Note that it's strongly recommended to invoke
+.Nm
+with
+.Fl o Ic posix
+to fully enjoy better compatibility to the
+.Tn POSIX
+standard (which is probably why you use
+.Nm
+over
+.Nm mksh
+in the first place);
+.Fl o Ic sh
+(possibly additionally to the above) may be needed for some legacy scripts.
.Sh LEGACY MODE
.Nm
currently has the following differences from
.Nm mksh :
.Bl -bullet
.It
-There is no explicit support for interactive use,
-nor any command line editing or history code.
-Hence,
-.Nm
-is not suitable as a user's login shell, either; use
-.Nm mksh
-instead.
-.It
The
.Ev KSH_VERSION
string identifies
.Nm
as
-.Dq LEGACY KSH
+.Dq Li LEGACY KSH
instead of
-.Dq MIRBSD KSH .
+.Dq Li 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
for the versions this document applies to.
.It
.Nm
-only offers the traditional ten file descriptors to scripts.
-.It
-.Nm
uses
.Tn POSIX
-arithmetics, which has quite a few implications:
-The data type for arithmetics is the host ISO C
+arithmetic, which has quite a few implications:
+The data type for arithmetic operations is the host
+.Tn ISO
+C
.Vt long
data type.
-Signed integer wraparound is Undefined Behaviour.
+Signed integer wraparound is Undefined Behaviour; this means that...
+.Bd -literal -offset indent
+$ echo $((2147483647 + 1))
+.Ed
+.Pp
+\&... is permitted to, e.g. delete all files on your system
+(the figure differs for non-32-bit systems, the rule doesn't).
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 \-1 is Undefined Behaviour.
The compiler is permitted to delete all data and crash the system
-if Undefined Behaviour occurs.
+if Undefined Behaviour occurs (see above for an example).
.It
The rotation arithmetic operators are not available.
.It
The shift arithmetic operators take all bits of the second operand into
account; if they exceed permitted precision, the result is unspecified.
.It
-The
-.Tn GNU
-.Nm bash
-extension &\*(Gt to redirect stdout and stderr in one go is not parsed.
-.It
-The
-.Nm mksh
-command line option
-.Fl T
-is not available.
-.It
Unless
.Ic set -o posix
is active,
.Xr getopt 1
command.
.It
-Unlike
-.At
-.Nm ksh ,
-.Nm mksh
-in
-.Fl o Ic posix
-or
-.Fl o Ic sh
-mode and
-.Nm lksh
-do not keep file descriptors \*(Gt 2 private from sub-processes.
-.It
-.Nm lksh
-undefines an alias when a
-.Tn POSIX
-function with the same name is defined,
-to make that function immediately callable.
-In
-.Nm mksh ,
-aliases have precedence; the name must be quoted or
-.Ic unalias Ns ed
-to access it.
-.It
Functions defined with the
.Ic function
reserved word share the shell options
.Sh SEE ALSO
.Xr mksh 1
.Pp
-.Pa https://www.mirbsd.org/mksh.htm
+.Pa http://www.mirbsd.org/mksh.htm
.Pp
-.Pa https://www.mirbsd.org/ksh\-chan.htm
+.Pa http://www.mirbsd.org/ksh\-chan.htm
.Sh CAVEATS
To use
.Nm
.Pa /bin/sh ,
compilation to enable
.Ic set -o posix
-by default is highly recommended for better standards compliance.
+by default if called as
+.Nm sh
+.Pq adding Dv \-DMKSH_BINSHPOSIX to Dv CPPFLAGS
+is highly recommended for better standards compliance.
+.Pp
+For better compatibility with legacy scripts, such as many
+.Tn Debian
+maintainer scripts, Upstart and SYSV init scripts, and other
+unfixed scripts, also adding the
+.Dv \-DMKSH_BINSHREDUCED
+compile-time option to enable
+.Em both
+.Ic set -o posix -o sh
+when the shell is run as
+.Nm sh ,
+as well as integrating the optional disrecommended
+.Xr printf 1
+builtin, might be necessary.
.Pp
.Nm
tries to make a cross between a legacy bourne/posix compatibl-ish
.Dq legacy
is not exactly specified.
.Pp
-The
-.Ic set
-built-in command does not have all options one would expect
-from a full-blown
-.Nm mksh
-or
-.Nm pdksh .
-.Pp
Talk to the
.Mx
development team using the mailing list at