Blame lksh.1

Packit Service 95ac19
.\" $MirOS: src/bin/mksh/lksh.1,v 1.23 2017/04/02 13:38:02 tg Exp $
Packit Service 95ac19
.\"-
Packit Service 95ac19
.\" Copyright (c) 2008, 2009, 2010, 2012, 2013, 2015, 2016, 2017
Packit Service 95ac19
.\"	mirabilos <m@mirbsd.org>
Packit Service 95ac19
.\"
Packit Service 95ac19
.\" Provided that these terms and disclaimer and all copyright notices
Packit Service 95ac19
.\" are retained or reproduced in an accompanying document, permission
Packit Service 95ac19
.\" is granted to deal in this work without restriction, including un‐
Packit Service 95ac19
.\" limited rights to use, publicly perform, distribute, sell, modify,
Packit Service 95ac19
.\" merge, give away, or sublicence.
Packit Service 95ac19
.\"
Packit Service 95ac19
.\" This work is provided “AS IS” and WITHOUT WARRANTY of any kind, to
Packit Service 95ac19
.\" the utmost extent permitted by applicable law, neither express nor
Packit Service 95ac19
.\" implied; without malicious intent or gross negligence. In no event
Packit Service 95ac19
.\" may a licensor, author or contributor be held liable for indirect,
Packit Service 95ac19
.\" direct, other damage, loss, or other issues arising in any way out
Packit Service 95ac19
.\" of dealing in the work, even if advised of the possibility of such
Packit Service 95ac19
.\" damage or existence of a defect, except proven that it results out
Packit Service 95ac19
.\" of said person’s immediate fault when using the work as intended.
Packit Service 95ac19
.\"-
Packit Service 95ac19
.\" Try to make GNU groff and AT&T nroff more compatible
Packit Service 95ac19
.\" * ` generates ‘ in gnroff, so use \`
Packit Service 95ac19
.\" * ' generates ’ in gnroff, \' generates ´, so use \*(aq
Packit Service 95ac19
.\" * - generates ‐ in gnroff, \- generates −, so .tr it to -
Packit Service 95ac19
.\"   thus use - for hyphens and \- for minus signs and option dashes
Packit Service 95ac19
.\" * ~ is size-reduced and placed atop in groff, so use \*(TI
Packit Service 95ac19
.\" * ^ is size-reduced and placed atop in groff, so use \*(ha
Packit Service 95ac19
.\" * \(en does not work in nroff, so use \*(en
Packit Service 95ac19
.\" * <>| are problematic, so redefine and use \*(Lt\*(Gt\*(Ba
Packit Service 95ac19
.\" Also make sure to use \& *before* a punctuation char that is to not
Packit Service 95ac19
.\" be interpreted as punctuation, and especially with two-letter words
Packit Service 95ac19
.\" but also (after) a period that does not end a sentence (“e.g.\&”).
Packit Service 95ac19
.\" The section after the "doc" macropackage has been loaded contains
Packit Service 95ac19
.\" additional code to convene between the UCB mdoc macropackage (and
Packit Service 95ac19
.\" its variant as BSD mdoc in groff) and the GNU mdoc macropackage.
Packit Service 95ac19
.\"
Packit Service 95ac19
.ie \n(.g \{\
Packit Service 95ac19
.	if ?\*[.T]?ascii? .tr \-\N'45'
Packit Service 95ac19
.	if ?\*[.T]?latin1? .tr \-\N'45'
Packit Service 95ac19
.	if ?\*[.T]?utf8? .tr \-\N'45'
Packit Service 95ac19
.	ds <= \[<=]
Packit Service 95ac19
.	ds >= \[>=]
Packit Service 95ac19
.	ds Rq \[rq]
Packit Service 95ac19
.	ds Lq \[lq]
Packit Service 95ac19
.	ds sL \(aq
Packit Service 95ac19
.	ds sR \(aq
Packit Service 95ac19
.	if ?\*[.T]?utf8? .ds sL `
Packit Service 95ac19
.	if ?\*[.T]?ps? .ds sL `
Packit Service 95ac19
.	if ?\*[.T]?utf8? .ds sR '
Packit Service 95ac19
.	if ?\*[.T]?ps? .ds sR '
Packit Service 95ac19
.	ds aq \(aq
Packit Service 95ac19
.	ds TI \(ti
Packit Service 95ac19
.	ds ha \(ha
Packit Service 95ac19
.	ds en \(en
Packit Service 95ac19
.\}
Packit Service 95ac19
.el \{\
Packit Service 95ac19
.	ds aq '
Packit Service 95ac19
.	ds TI ~
Packit Service 95ac19
.	ds ha ^
Packit Service 95ac19
.	ds en \(em
Packit Service 95ac19
.\}
Packit Service 95ac19
.\"
Packit Service 95ac19
.\" Implement .Dd with the Mdocdate RCS keyword
Packit Service 95ac19
.\"
Packit Service 95ac19
.rn Dd xD
Packit Service 95ac19
.de Dd
Packit Service 95ac19
.ie ?\\$1?$Mdocdate:? \{\
Packit Service 95ac19
.	xD \\$2 \\$3, \\$4
Packit Service 95ac19
.\}
Packit Service 95ac19
.el .xD \\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8
Packit Service 95ac19
..
Packit Service 95ac19
.\"
Packit Service 95ac19
.\" .Dd must come before definition of .Mx, because when called
Packit Service 95ac19
.\" with -mandoc, it might implement .Mx itself, but we want to
Packit Service 95ac19
.\" use our own definition. And .Dd must come *first*, always.
Packit Service 95ac19
.\"
Packit Service 95ac19
.Dd $Mdocdate: April 2 2017 $
Packit Service 95ac19
.\"
Packit Service 95ac19
.\" Check which macro package we use, and do other -mdoc setup.
Packit Service 95ac19
.\"
Packit Service 95ac19
.ie \n(.g \{\
Packit Service 95ac19
.	if ?\*[.T]?utf8? .tr \[la]\*(Lt
Packit Service 95ac19
.	if ?\*[.T]?utf8? .tr \[ra]\*(Gt
Packit Service 95ac19
.	ie d volume-ds-1 .ds tT gnu
Packit Service 95ac19
.	el .ds tT bsd
Packit Service 95ac19
.\}
Packit Service 95ac19
.el .ds tT ucb
Packit Service 95ac19
.\"
Packit Service 95ac19
.\" Implement .Mx (MirBSD)
Packit Service 95ac19
.\"
Packit Service 95ac19
.ie "\*(tT"gnu" \{\
Packit Service 95ac19
.	eo
Packit Service 95ac19
.	de Mx
Packit Service 95ac19
.	nr curr-font \n[.f]
Packit Service 95ac19
.	nr curr-size \n[.ps]
Packit Service 95ac19
.	ds str-Mx \f[\n[curr-font]]\s[\n[curr-size]u]
Packit Service 95ac19
.	ds str-Mx1 \*[Tn-font-size]\%MirOS\*[str-Mx]
Packit Service 95ac19
.	if !\n[arg-limit] \
Packit Service 95ac19
.	if \n[.$] \{\
Packit Service 95ac19
.	ds macro-name Mx
Packit Service 95ac19
.	parse-args \$@
Packit Service 95ac19
.	\}
Packit Service 95ac19
.	if (\n[arg-limit] > \n[arg-ptr]) \{\
Packit Service 95ac19
.	nr arg-ptr +1
Packit Service 95ac19
.	ie (\n[type\n[arg-ptr]] == 2) \
Packit Service 95ac19
.	as str-Mx1 \~\*[arg\n[arg-ptr]]
Packit Service 95ac19
.	el \
Packit Service 95ac19
.	nr arg-ptr -1
Packit Service 95ac19
.	\}
Packit Service 95ac19
.	ds arg\n[arg-ptr] "\*[str-Mx1]
Packit Service 95ac19
.	nr type\n[arg-ptr] 2
Packit Service 95ac19
.	ds space\n[arg-ptr] "\*[space]
Packit Service 95ac19
.	nr num-args (\n[arg-limit] - \n[arg-ptr])
Packit Service 95ac19
.	nr arg-limit \n[arg-ptr]
Packit Service 95ac19
.	if \n[num-args] \
Packit Service 95ac19
.	parse-space-vector
Packit Service 95ac19
.	print-recursive
Packit Service 95ac19
..
Packit Service 95ac19
.	ec
Packit Service 95ac19
.	ds sP \s0
Packit Service 95ac19
.	ds tN \*[Tn-font-size]
Packit Service 95ac19
.\}
Packit Service 95ac19
.el \{\
Packit Service 95ac19
.	de Mx
Packit Service 95ac19
.	nr cF \\n(.f
Packit Service 95ac19
.	nr cZ \\n(.s
Packit Service 95ac19
.	ds aa \&\f\\n(cF\s\\n(cZ
Packit Service 95ac19
.	if \\n(aC==0 \{\
Packit Service 95ac19
.		ie \\n(.$==0 \&MirOS\\*(aa
Packit Service 95ac19
.		el .aV \\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8 \\$9
Packit Service 95ac19
.	\}
Packit Service 95ac19
.	if \\n(aC>\\n(aP \{\
Packit Service 95ac19
.		nr aP \\n(aP+1
Packit Service 95ac19
.		ie \\n(C\\n(aP==2 \{\
Packit Service 95ac19
.			as b1 \&MirOS\ #\&\\*(A\\n(aP\\*(aa
Packit Service 95ac19
.			ie \\n(aC>\\n(aP \{\
Packit Service 95ac19
.				nr aP \\n(aP+1
Packit Service 95ac19
.				nR
Packit Service 95ac19
.			\}
Packit Service 95ac19
.			el .aZ
Packit Service 95ac19
.		\}
Packit Service 95ac19
.		el \{\
Packit Service 95ac19
.			as b1 \&MirOS\\*(aa
Packit Service 95ac19
.			nR
Packit Service 95ac19
.		\}
Packit Service 95ac19
.	\}
Packit Service 95ac19
..
Packit Service 95ac19
.\}
Packit Service 95ac19
.\"-
Packit Service 95ac19
.Dt LKSH 1
Packit Service 95ac19
.Os MirBSD
Packit Service 95ac19
.Sh NAME
Packit Service 95ac19
.Nm lksh
Packit Service 95ac19
.Nd Legacy Korn shell built on mksh
Packit Service 95ac19
.Sh SYNOPSIS
Packit Service 95ac19
.Nm
Packit Service 95ac19
.Bk -words
Packit Service 95ac19
.Op Fl +abCefhiklmnprUuvXx
Packit Service 95ac19
.Op Fl +o Ar opt
Packit Service 95ac19
.Oo
Packit Service 95ac19
.Fl c Ar string \*(Ba
Packit Service 95ac19
.Fl s \*(Ba
Packit Service 95ac19
.Ar file
Packit Service 95ac19
.Op Ar args ...
Packit Service 95ac19
.Oc
Packit Service 95ac19
.Ek
Packit Service 95ac19
.Sh DESCRIPTION
Packit Service 95ac19
.Nm
Packit Service 95ac19
is a command interpreter intended exclusively for running legacy
Packit Service 95ac19
shell scripts.
Packit Service 95ac19
It is built on
Packit Service 95ac19
.Nm mksh ;
Packit Service 95ac19
refer to its manual page for details on the scripting language.
Packit Service 95ac19
It is recommended to port scripts to
Packit Service 95ac19
.Nm mksh
Packit Service 95ac19
instead of relying on legacy or objectionable POSIX-mandated behaviour,
Packit Service 95ac19
since the MirBSD Korn Shell scripting language is much more consistent.
Packit Service 95ac19
.Pp
Packit Service 95ac19
Do not use
Packit Service 95ac19
.Nm
Packit Service 95ac19
as an interactive or login shell; use
Packit Service 95ac19
.Nm mksh
Packit Service 95ac19
instead.
Packit Service 95ac19
.Pp
Packit Service 95ac19
Note that it's strongly recommended to invoke
Packit Service 95ac19
.Nm
Packit Service 95ac19
with
Packit Service 95ac19
.Fl o Ic posix
Packit Service 95ac19
to fully enjoy better compatibility to the
Packit Service 95ac19
.Tn POSIX
Packit Service 95ac19
standard (which is probably why you use
Packit Service 95ac19
.Nm
Packit Service 95ac19
over
Packit Service 95ac19
.Nm mksh
Packit Service 95ac19
in the first place);
Packit Service 95ac19
.Fl o Ic sh
Packit Service 95ac19
(possibly additionally to the above) may be needed for some legacy scripts.
Packit Service 95ac19
.Sh LEGACY MODE
Packit Service 95ac19
.Nm
Packit Service 95ac19
currently has the following differences from
Packit Service 95ac19
.Nm mksh :
Packit Service 95ac19
.Bl -bullet
Packit Service 95ac19
.It
Packit Service 95ac19
The
Packit Service 95ac19
.Ev KSH_VERSION
Packit Service 95ac19
string identifies
Packit Service 95ac19
.Nm
Packit Service 95ac19
as
Packit Service 95ac19
.Dq Li LEGACY KSH
Packit Service 95ac19
instead of
Packit Service 95ac19
.Dq Li MIRBSD KSH .
Packit Service 95ac19
Note that the rest of the version string is identical between
Packit Service 95ac19
the two shell flavours, and the behaviour and differences can
Packit Service 95ac19
change between versions; see the accompanying manual page
Packit Service 95ac19
.Xr mksh 1
Packit Service 95ac19
for the versions this document applies to.
Packit Service 95ac19
.It
Packit Service 95ac19
.Nm
Packit Service 95ac19
uses
Packit Service 95ac19
.Tn POSIX
Packit Service 95ac19
arithmetic, which has quite a few implications:
Packit Service 95ac19
The data type for arithmetic operations is the host
Packit Service 95ac19
.Tn ISO
Packit Service 95ac19
C
Packit Service 95ac19
.Vt long
Packit Service 95ac19
data type.
Packit Service 95ac19
Signed integer wraparound is Undefined Behaviour; this means that...
Packit Service 95ac19
.Bd -literal -offset indent
Packit Service 95ac19
$ echo $((2147483647 + 1))
Packit Service 95ac19
.Ed
Packit Service 95ac19
.Pp
Packit Service 95ac19
\&... is permitted to, e.g. delete all files on your system
Packit Service 95ac19
(the figure differs for non-32-bit systems, the rule doesn't).
Packit Service 95ac19
The sign of the result of a modulo operation with at least one
Packit Service 95ac19
negative operand is unspecified.
Packit Service 95ac19
Shift operations on negative numbers are unspecified.
Packit Service 95ac19
Division of the largest negative number by \-1 is Undefined Behaviour.
Packit Service 95ac19
The compiler is permitted to delete all data and crash the system
Packit Service 95ac19
if Undefined Behaviour occurs (see above for an example).
Packit Service 95ac19
.It
Packit Service 95ac19
The rotation arithmetic operators are not available.
Packit Service 95ac19
.It
Packit Service 95ac19
The shift arithmetic operators take all bits of the second operand into
Packit Service 95ac19
account; if they exceed permitted precision, the result is unspecified.
Packit Service 95ac19
.It
Packit Service 95ac19
Unless
Packit Service 95ac19
.Ic set -o posix
Packit Service 95ac19
is active,
Packit Service 95ac19
.Nm
Packit Service 95ac19
always uses traditional mode for constructs like:
Packit Service 95ac19
.Bd -literal -offset indent
Packit Service 95ac19
$ set -- $(getopt ab:c "$@")
Packit Service 95ac19
$ echo $?
Packit Service 95ac19
.Ed
Packit Service 95ac19
.Pp
Packit Service 95ac19
POSIX mandates this to show 0, but traditional mode
Packit Service 95ac19
passes through the errorlevel from the
Packit Service 95ac19
.Xr getopt 1
Packit Service 95ac19
command.
Packit Service 95ac19
.It
Packit Service 95ac19
Functions defined with the
Packit Service 95ac19
.Ic function
Packit Service 95ac19
reserved word share the shell options
Packit Service 95ac19
.Pq Ic set -o
Packit Service 95ac19
instead of locally scoping them.
Packit Service 95ac19
.El
Packit Service 95ac19
.Sh SEE ALSO
Packit Service 95ac19
.Xr mksh 1
Packit Service 95ac19
.Pp
Packit Service 95ac19
.Pa http://www.mirbsd.org/mksh.htm
Packit Service 95ac19
.Pp
Packit Service 95ac19
.Pa http://www.mirbsd.org/ksh\-chan.htm
Packit Service 95ac19
.Sh CAVEATS
Packit Service 95ac19
To use
Packit Service 95ac19
.Nm
Packit Service 95ac19
as
Packit Service 95ac19
.Pa /bin/sh ,
Packit Service 95ac19
compilation to enable
Packit Service 95ac19
.Ic set -o posix
Packit Service 95ac19
by default if called as
Packit Service 95ac19
.Nm sh
Packit Service 95ac19
.Pq adding Dv \-DMKSH_BINSHPOSIX to Dv CPPFLAGS
Packit Service 95ac19
is highly recommended for better standards compliance.
Packit Service 95ac19
.Pp
Packit Service 95ac19
For better compatibility with legacy scripts, such as many
Packit Service 95ac19
.Tn Debian
Packit Service 95ac19
maintainer scripts, Upstart and SYSV init scripts, and other
Packit Service 95ac19
unfixed scripts, also adding the
Packit Service 95ac19
.Dv \-DMKSH_BINSHREDUCED
Packit Service 95ac19
compile-time option to enable
Packit Service 95ac19
.Em both
Packit Service 95ac19
.Ic set -o posix -o sh
Packit Service 95ac19
when the shell is run as
Packit Service 95ac19
.Nm sh ,
Packit Service 95ac19
as well as integrating the optional disrecommended
Packit Service 95ac19
.Xr printf 1
Packit Service 95ac19
builtin, might be necessary.
Packit Service 95ac19
.Pp
Packit Service 95ac19
.Nm
Packit Service 95ac19
tries to make a cross between a legacy bourne/posix compatibl-ish
Packit Service 95ac19
shell and a legacy pdksh-alike but
Packit Service 95ac19
.Dq legacy
Packit Service 95ac19
is not exactly specified.
Packit Service 95ac19
.Pp
Packit Service 95ac19
Talk to the
Packit Service 95ac19
.Mx
Packit Service 95ac19
development team using the mailing list at
Packit Service 95ac19
.Aq miros\-mksh@mirbsd.org
Packit Service 95ac19
or the
Packit Service 95ac19
.Li \&#\&!/bin/mksh
Packit Service 95ac19
.Pq or Li \&#ksh
Packit Service 95ac19
IRC channel at
Packit Service 95ac19
.Pa irc.freenode.net
Packit Service 95ac19
.Pq Port 6697 SSL, 6667 unencrypted
Packit Service 95ac19
if you need any further quirks or assistance,
Packit Service 95ac19
and consider migrating your legacy scripts to work with
Packit Service 95ac19
.Nm mksh
Packit Service 95ac19
instead of requiring
Packit Service 95ac19
.Nm .