2016-02-11 21:12:09 +01:00
|
|
|
|
.\" $MirOS: src/bin/mksh/lksh.1,v 1.17 2016/02/11 20:12:09 tg Exp $
|
2013-04-27 20:13:58 +02:00
|
|
|
|
.\"-
|
2016-02-11 21:12:09 +01:00
|
|
|
|
.\" Copyright (c) 2008, 2009, 2010, 2012, 2013, 2015, 2016
|
2015-10-09 21:28:20 +02:00
|
|
|
|
.\" mirabilos <m@mirbsd.org>
|
2013-04-27 20:50:25 +02:00
|
|
|
|
.\"
|
|
|
|
|
.\" Provided that these terms and disclaimer and all copyright notices
|
|
|
|
|
.\" are retained or reproduced in an accompanying document, permission
|
|
|
|
|
.\" is granted to deal in this work without restriction, including un‐
|
|
|
|
|
.\" limited rights to use, publicly perform, distribute, sell, modify,
|
|
|
|
|
.\" merge, give away, or sublicence.
|
|
|
|
|
.\"
|
|
|
|
|
.\" This work is provided “AS IS” and WITHOUT WARRANTY of any kind, to
|
|
|
|
|
.\" the utmost extent permitted by applicable law, neither express nor
|
|
|
|
|
.\" implied; without malicious intent or gross negligence. In no event
|
|
|
|
|
.\" may a licensor, author or contributor be held liable for indirect,
|
|
|
|
|
.\" direct, other damage, loss, or other issues arising in any way out
|
|
|
|
|
.\" of dealing in the work, even if advised of the possibility of such
|
|
|
|
|
.\" damage or existence of a defect, except proven that it results out
|
|
|
|
|
.\" of said person’s immediate fault when using the work as intended.
|
2013-04-27 20:13:58 +02:00
|
|
|
|
.\"-
|
|
|
|
|
.\" Try to make GNU groff and AT&T nroff more compatible
|
|
|
|
|
.\" * ` generates ‘ in gnroff, so use \`
|
|
|
|
|
.\" * ' generates ’ in gnroff, \' generates ´, so use \*(aq
|
|
|
|
|
.\" * - generates ‐ in gnroff, \- generates −, so .tr it to -
|
|
|
|
|
.\" thus use - for hyphens and \- for minus signs and option dashes
|
|
|
|
|
.\" * ~ is size-reduced and placed atop in groff, so use \*(TI
|
|
|
|
|
.\" * ^ 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
|
2016-02-11 21:12:09 +01:00
|
|
|
|
.\" 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.\&”).
|
2013-04-27 20:13:58 +02:00
|
|
|
|
.\" 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.
|
|
|
|
|
.\"
|
|
|
|
|
.ie \n(.g \{\
|
|
|
|
|
. if \*[.T]ascii .tr \-\N'45'
|
|
|
|
|
. if \*[.T]latin1 .tr \-\N'45'
|
|
|
|
|
. if \*[.T]utf8 .tr \-\N'45'
|
|
|
|
|
. ds <= \[<=]
|
|
|
|
|
. ds >= \[>=]
|
|
|
|
|
. ds Rq \[rq]
|
|
|
|
|
. ds Lq \[lq]
|
|
|
|
|
. ds sL \(aq
|
|
|
|
|
. ds sR \(aq
|
|
|
|
|
. if \*[.T]utf8 .ds sL `
|
|
|
|
|
. if \*[.T]ps .ds sL `
|
|
|
|
|
. if \*[.T]utf8 .ds sR '
|
|
|
|
|
. if \*[.T]ps .ds sR '
|
|
|
|
|
. ds aq \(aq
|
|
|
|
|
. ds TI \(ti
|
|
|
|
|
. ds ha \(ha
|
|
|
|
|
. ds en \(en
|
|
|
|
|
.\}
|
|
|
|
|
.el \{\
|
|
|
|
|
. ds aq '
|
|
|
|
|
. ds TI ~
|
|
|
|
|
. ds ha ^
|
|
|
|
|
. ds en \(em
|
|
|
|
|
.\}
|
|
|
|
|
.\"
|
|
|
|
|
.\" Implement .Dd with the Mdocdate RCS keyword
|
|
|
|
|
.\"
|
|
|
|
|
.rn Dd xD
|
|
|
|
|
.de Dd
|
|
|
|
|
.ie \\$1$Mdocdate: \{\
|
|
|
|
|
. xD \\$2 \\$3, \\$4
|
|
|
|
|
.\}
|
|
|
|
|
.el .xD \\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8
|
|
|
|
|
..
|
|
|
|
|
.\"
|
|
|
|
|
.\" .Dd must come before definition of .Mx, because when called
|
|
|
|
|
.\" with -mandoc, it might implement .Mx itself, but we want to
|
|
|
|
|
.\" use our own definition. And .Dd must come *first*, always.
|
|
|
|
|
.\"
|
2016-02-11 21:12:09 +01:00
|
|
|
|
.Dd $Mdocdate: February 11 2016 $
|
2013-04-27 20:13:58 +02:00
|
|
|
|
.\"
|
|
|
|
|
.\" Check which macro package we use, and do other -mdoc setup.
|
|
|
|
|
.\"
|
|
|
|
|
.ie \n(.g \{\
|
|
|
|
|
. if \*[.T]utf8 .tr \[la]\*(Lt
|
|
|
|
|
. if \*[.T]utf8 .tr \[ra]\*(Gt
|
|
|
|
|
. ie d volume-ds-1 .ds tT gnu
|
|
|
|
|
. el .ds tT bsd
|
|
|
|
|
.\}
|
|
|
|
|
.el .ds tT ucb
|
|
|
|
|
.\"
|
|
|
|
|
.\" Implement .Mx (MirBSD)
|
|
|
|
|
.\"
|
|
|
|
|
.ie "\*(tT"gnu" \{\
|
|
|
|
|
. eo
|
|
|
|
|
. de Mx
|
|
|
|
|
. nr curr-font \n[.f]
|
|
|
|
|
. nr curr-size \n[.ps]
|
|
|
|
|
. ds str-Mx \f[\n[curr-font]]\s[\n[curr-size]u]
|
|
|
|
|
. ds str-Mx1 \*[Tn-font-size]\%MirOS\*[str-Mx]
|
|
|
|
|
. if !\n[arg-limit] \
|
|
|
|
|
. if \n[.$] \{\
|
|
|
|
|
. ds macro-name Mx
|
|
|
|
|
. parse-args \$@
|
|
|
|
|
. \}
|
|
|
|
|
. if (\n[arg-limit] > \n[arg-ptr]) \{\
|
|
|
|
|
. nr arg-ptr +1
|
|
|
|
|
. ie (\n[type\n[arg-ptr]] == 2) \
|
|
|
|
|
. as str-Mx1 \~\*[arg\n[arg-ptr]]
|
|
|
|
|
. el \
|
|
|
|
|
. nr arg-ptr -1
|
|
|
|
|
. \}
|
|
|
|
|
. ds arg\n[arg-ptr] "\*[str-Mx1]
|
|
|
|
|
. nr type\n[arg-ptr] 2
|
|
|
|
|
. ds space\n[arg-ptr] "\*[space]
|
|
|
|
|
. nr num-args (\n[arg-limit] - \n[arg-ptr])
|
|
|
|
|
. nr arg-limit \n[arg-ptr]
|
|
|
|
|
. if \n[num-args] \
|
|
|
|
|
. parse-space-vector
|
|
|
|
|
. print-recursive
|
|
|
|
|
..
|
|
|
|
|
. ec
|
|
|
|
|
. ds sP \s0
|
|
|
|
|
. ds tN \*[Tn-font-size]
|
|
|
|
|
.\}
|
|
|
|
|
.el \{\
|
|
|
|
|
. de Mx
|
|
|
|
|
. nr cF \\n(.f
|
|
|
|
|
. nr cZ \\n(.s
|
|
|
|
|
. ds aa \&\f\\n(cF\s\\n(cZ
|
|
|
|
|
. if \\n(aC==0 \{\
|
|
|
|
|
. ie \\n(.$==0 \&MirOS\\*(aa
|
|
|
|
|
. el .aV \\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8 \\$9
|
|
|
|
|
. \}
|
|
|
|
|
. if \\n(aC>\\n(aP \{\
|
|
|
|
|
. nr aP \\n(aP+1
|
|
|
|
|
. ie \\n(C\\n(aP==2 \{\
|
|
|
|
|
. as b1 \&MirOS\ #\&\\*(A\\n(aP\\*(aa
|
|
|
|
|
. ie \\n(aC>\\n(aP \{\
|
|
|
|
|
. nr aP \\n(aP+1
|
|
|
|
|
. nR
|
|
|
|
|
. \}
|
|
|
|
|
. el .aZ
|
|
|
|
|
. \}
|
|
|
|
|
. el \{\
|
|
|
|
|
. as b1 \&MirOS\\*(aa
|
|
|
|
|
. nR
|
|
|
|
|
. \}
|
|
|
|
|
. \}
|
|
|
|
|
..
|
|
|
|
|
.\}
|
|
|
|
|
.\"-
|
|
|
|
|
.Dt LKSH 1
|
|
|
|
|
.Os MirBSD
|
|
|
|
|
.Sh NAME
|
|
|
|
|
.Nm lksh
|
|
|
|
|
.Nd Legacy Korn shell built on mksh
|
|
|
|
|
.Sh SYNOPSIS
|
|
|
|
|
.Nm
|
|
|
|
|
.Bk -words
|
|
|
|
|
.Op Fl +abCefhiklmnprUuvXx
|
|
|
|
|
.Op Fl +o Ar opt
|
|
|
|
|
.Oo
|
|
|
|
|
.Fl c Ar string \*(Ba
|
|
|
|
|
.Fl s \*(Ba
|
|
|
|
|
.Ar file
|
|
|
|
|
.Op Ar args ...
|
|
|
|
|
.Oc
|
|
|
|
|
.Ek
|
|
|
|
|
.Sh DESCRIPTION
|
|
|
|
|
.Nm
|
2013-04-27 20:50:25 +02:00
|
|
|
|
is a command interpreter intended exclusively for running legacy
|
2013-04-27 20:13:58 +02:00
|
|
|
|
shell scripts.
|
|
|
|
|
It is built on
|
|
|
|
|
.Nm mksh ;
|
|
|
|
|
refer to its manual page for details on the scripting language.
|
2013-04-27 20:50:25 +02:00
|
|
|
|
It is recommended to port scripts to
|
|
|
|
|
.Nm mksh
|
|
|
|
|
instead of relying on legacy or idiotic POSIX-mandated behaviour,
|
|
|
|
|
since the MirBSD Korn Shell scripting language is much more consistent.
|
2015-10-09 22:33:49 +02:00
|
|
|
|
.Pp
|
|
|
|
|
Note that it's strongly recommended to invoke
|
|
|
|
|
.Nm
|
|
|
|
|
with at least the
|
|
|
|
|
.Fl o Ic posix
|
|
|
|
|
option, if not both that
|
|
|
|
|
.Em and Fl o Ic sh ,
|
|
|
|
|
to fully enjoy better compatibility to the
|
|
|
|
|
.Tn POSIX
|
|
|
|
|
standard (which is probably why you use
|
|
|
|
|
.Nm
|
|
|
|
|
over
|
|
|
|
|
.Nm mksh
|
|
|
|
|
in the first place) or legacy scripts, respectively.
|
2013-04-27 20:13:58 +02:00
|
|
|
|
.Sh LEGACY MODE
|
|
|
|
|
.Nm
|
2015-03-21 01:12:46 +01:00
|
|
|
|
currently has the following differences from
|
2013-04-27 20:13:58 +02:00
|
|
|
|
.Nm mksh :
|
|
|
|
|
.Bl -bullet
|
|
|
|
|
.It
|
2015-10-09 21:28:20 +02:00
|
|
|
|
.\"XXX TODO: remove (some systems may wish to have lksh as ksh)
|
2013-04-27 20:13:58 +02:00
|
|
|
|
There is no explicit support for interactive use,
|
2013-05-02 22:21:45 +02:00
|
|
|
|
nor any command line editing or history code.
|
2013-04-27 20:13:58 +02:00
|
|
|
|
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
|
|
|
|
|
instead of
|
|
|
|
|
.Dq MIRBSD KSH .
|
2015-03-21 01:12:46 +01:00
|
|
|
|
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
|
|
|
|
|
.Xr mksh 1
|
|
|
|
|
for the versions this document applies to.
|
2013-04-27 20:13:58 +02:00
|
|
|
|
.It
|
2013-05-02 22:21:45 +02:00
|
|
|
|
.Nm
|
|
|
|
|
uses
|
|
|
|
|
.Tn POSIX
|
|
|
|
|
arithmetics, which has quite a few implications:
|
2015-10-09 22:33:49 +02:00
|
|
|
|
The data type for arithmetics is the host
|
|
|
|
|
.Tn ISO
|
|
|
|
|
C
|
2013-05-02 22:21:45 +02:00
|
|
|
|
.Vt long
|
|
|
|
|
data type.
|
2015-10-09 22:33:49 +02:00
|
|
|
|
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).
|
2013-05-02 22:21:45 +02:00
|
|
|
|
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
|
2015-10-09 22:33:49 +02:00
|
|
|
|
if Undefined Behaviour occurs (see above for an example).
|
|
|
|
|
.It
|
|
|
|
|
.Nm
|
|
|
|
|
only offers the traditional ten file descriptors to scripts.
|
2013-05-02 22:21:45 +02:00
|
|
|
|
.It
|
2015-10-09 21:28:20 +02:00
|
|
|
|
.\"XXX TODO: move this to FPOSIX
|
2013-05-02 22:21:45 +02:00
|
|
|
|
The rotation arithmetic operators are not available.
|
2013-04-27 20:13:58 +02:00
|
|
|
|
.It
|
2013-05-02 22:21:45 +02:00
|
|
|
|
The shift arithmetic operators take all bits of the second operand into
|
|
|
|
|
account; if they exceed permitted precision, the result is unspecified.
|
|
|
|
|
.It
|
2015-10-09 21:28:20 +02:00
|
|
|
|
.\"XXX TODO: move this to FPOSIX
|
2013-05-02 22:21:45 +02:00
|
|
|
|
The
|
2013-04-27 20:13:58 +02:00
|
|
|
|
.Tn GNU
|
2013-05-02 22:21:45 +02:00
|
|
|
|
.Nm bash
|
|
|
|
|
extension &\*(Gt to redirect stdout and stderr in one go is not parsed.
|
|
|
|
|
.It
|
2015-10-09 21:28:20 +02:00
|
|
|
|
.\"XXX TODO: drop along with allowing interactivity
|
2013-05-02 22:21:45 +02:00
|
|
|
|
The
|
2013-04-27 20:13:58 +02:00
|
|
|
|
.Nm mksh
|
2013-05-02 22:21:45 +02:00
|
|
|
|
command line option
|
|
|
|
|
.Fl T
|
|
|
|
|
is not available.
|
2013-04-27 20:13:58 +02:00
|
|
|
|
.It
|
2013-05-02 22:21:45 +02:00
|
|
|
|
Unless
|
|
|
|
|
.Ic set -o posix
|
|
|
|
|
is active,
|
2013-04-27 20:13:58 +02:00
|
|
|
|
.Nm
|
|
|
|
|
always uses traditional mode for constructs like:
|
|
|
|
|
.Bd -literal -offset indent
|
|
|
|
|
$ set -- $(getopt ab:c "$@")
|
|
|
|
|
$ echo $?
|
|
|
|
|
.Ed
|
|
|
|
|
.Pp
|
|
|
|
|
POSIX mandates this to show 0, but traditional mode
|
|
|
|
|
passes through the errorlevel from the
|
|
|
|
|
.Xr getopt 1
|
|
|
|
|
command.
|
|
|
|
|
.It
|
2015-10-09 21:28:20 +02:00
|
|
|
|
.\"XXX TODO: move to FPOSIX/FSH
|
2015-03-21 00:37:29 +01:00
|
|
|
|
Unlike
|
2013-04-27 20:13:58 +02:00
|
|
|
|
.At
|
|
|
|
|
.Nm ksh ,
|
2015-03-21 00:37:29 +01:00
|
|
|
|
.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.
|
2015-03-21 00:37:55 +01:00
|
|
|
|
.It
|
2015-04-12 01:28:21 +02:00
|
|
|
|
Functions defined with the
|
|
|
|
|
.Ic function
|
2015-04-13 00:32:12 +02:00
|
|
|
|
reserved word share the shell options
|
2015-04-12 01:28:21 +02:00
|
|
|
|
.Pq Ic set -o
|
|
|
|
|
instead of locally scoping them.
|
2013-04-27 20:13:58 +02:00
|
|
|
|
.El
|
|
|
|
|
.Sh SEE ALSO
|
|
|
|
|
.Xr mksh 1
|
|
|
|
|
.Pp
|
|
|
|
|
.Pa https://www.mirbsd.org/mksh.htm
|
|
|
|
|
.Pp
|
|
|
|
|
.Pa https://www.mirbsd.org/ksh\-chan.htm
|
|
|
|
|
.Sh CAVEATS
|
2015-12-12 23:25:15 +01:00
|
|
|
|
The distinction between the shell variants
|
|
|
|
|
.Pq Nm lksh / Nm mksh
|
|
|
|
|
and shell flags
|
|
|
|
|
.Pq Fl o Ic posix / Ic sh
|
|
|
|
|
will be reworked for an upcoming release.
|
|
|
|
|
.Pp
|
2013-05-22 20:18:06 +02:00
|
|
|
|
To use
|
|
|
|
|
.Nm
|
|
|
|
|
as
|
|
|
|
|
.Pa /bin/sh ,
|
|
|
|
|
compilation to enable
|
|
|
|
|
.Ic set -o posix
|
2015-10-09 22:33:49 +02:00
|
|
|
|
by default if called as
|
|
|
|
|
.Nm sh
|
|
|
|
|
is highly recommended for better standards compliance.
|
|
|
|
|
For better compatibility with legacy scripts, such as many
|
|
|
|
|
.Tn Debian
|
|
|
|
|
maintainer scripts, Upstart and SYSV init scripts, and other
|
|
|
|
|
unfixed scripts, using the compile-time options for enabling
|
|
|
|
|
.Em both
|
|
|
|
|
.Ic set -o posix -o sh
|
|
|
|
|
when the shell is run as
|
|
|
|
|
.Nm sh
|
|
|
|
|
is recommended.
|
2013-05-22 20:18:06 +02:00
|
|
|
|
.Pp
|
2013-04-27 20:13:58 +02:00
|
|
|
|
.Nm
|
|
|
|
|
tries to make a cross between a legacy bourne/posix compatibl-ish
|
|
|
|
|
shell and a legacy pdksh-alike but
|
|
|
|
|
.Dq legacy
|
|
|
|
|
is not exactly specified.
|
|
|
|
|
.Pp
|
|
|
|
|
The
|
|
|
|
|
.Ic set
|
2015-10-09 22:33:49 +02:00
|
|
|
|
built-in command does not currently have all options one would expect
|
2013-04-27 20:13:58 +02:00
|
|
|
|
from a full-blown
|
|
|
|
|
.Nm mksh
|
|
|
|
|
or
|
|
|
|
|
.Nm pdksh .
|
|
|
|
|
.Pp
|
|
|
|
|
Talk to the
|
|
|
|
|
.Mx
|
|
|
|
|
development team using the mailing list at
|
|
|
|
|
.Aq miros\-mksh@mirbsd.org
|
|
|
|
|
or the
|
|
|
|
|
.Li \&#\&!/bin/mksh
|
|
|
|
|
.Pq or Li \&#ksh
|
|
|
|
|
IRC channel at
|
|
|
|
|
.Pa irc.freenode.net
|
|
|
|
|
.Pq Port 6697 SSL, 6667 unencrypted
|
|
|
|
|
if you need any further quirks or assistance,
|
|
|
|
|
and consider migrating your legacy scripts to work with
|
|
|
|
|
.Nm mksh
|
|
|
|
|
instead of requiring
|
|
|
|
|
.Nm .
|