blob: c3a82cb1d1cf7fdd9f6b958af15069018552f6b6 [file] [log] [blame]
Elliott Hughesa3c3f962017-04-12 16:52:30 -07001.\" $MirOS: src/bin/mksh/lksh.1,v 1.23 2017/04/02 13:38:02 tg Exp $
Thorsten Glaser811a5752013-07-25 14:24:45 +00002.\"-
Elliott Hughesa3c3f962017-04-12 16:52:30 -07003.\" Copyright (c) 2008, 2009, 2010, 2012, 2013, 2015, 2016, 2017
Elliott Hughesfc0307d2016-02-02 15:26:47 -08004.\" mirabilos <m@mirbsd.org>
Thorsten Glaser811a5752013-07-25 14:24:45 +00005.\"
6.\" Provided that these terms and disclaimer and all copyright notices
7.\" are retained or reproduced in an accompanying document, permission
8.\" is granted to deal in this work without restriction, including un‐
9.\" limited rights to use, publicly perform, distribute, sell, modify,
10.\" merge, give away, or sublicence.
11.\"
12.\" This work is provided “AS IS” and WITHOUT WARRANTY of any kind, to
13.\" the utmost extent permitted by applicable law, neither express nor
14.\" implied; without malicious intent or gross negligence. In no event
15.\" may a licensor, author or contributor be held liable for indirect,
16.\" direct, other damage, loss, or other issues arising in any way out
17.\" of dealing in the work, even if advised of the possibility of such
18.\" damage or existence of a defect, except proven that it results out
19.\" of said person’s immediate fault when using the work as intended.
20.\"-
21.\" Try to make GNU groff and AT&T nroff more compatible
22.\" * ` generates ‘ in gnroff, so use \`
23.\" * ' generates ’ in gnroff, \' generates ´, so use \*(aq
24.\" * - generates ‐ in gnroff, \- generates −, so .tr it to -
25.\" thus use - for hyphens and \- for minus signs and option dashes
26.\" * ~ is size-reduced and placed atop in groff, so use \*(TI
27.\" * ^ is size-reduced and placed atop in groff, so use \*(ha
28.\" * \(en does not work in nroff, so use \*(en
29.\" * <>| are problematic, so redefine and use \*(Lt\*(Gt\*(Ba
Elliott Hughes77740fc2016-08-12 15:06:53 -070030.\" Also make sure to use \& *before* a punctuation char that is to not
31.\" be interpreted as punctuation, and especially with two-letter words
32.\" but also (after) a period that does not end a sentence (“e.g.\&”).
Thorsten Glaser811a5752013-07-25 14:24:45 +000033.\" The section after the "doc" macropackage has been loaded contains
34.\" additional code to convene between the UCB mdoc macropackage (and
35.\" its variant as BSD mdoc in groff) and the GNU mdoc macropackage.
36.\"
37.ie \n(.g \{\
38. if \*[.T]ascii .tr \-\N'45'
39. if \*[.T]latin1 .tr \-\N'45'
40. if \*[.T]utf8 .tr \-\N'45'
41. ds <= \[<=]
42. ds >= \[>=]
43. ds Rq \[rq]
44. ds Lq \[lq]
45. ds sL \(aq
46. ds sR \(aq
47. if \*[.T]utf8 .ds sL `
48. if \*[.T]ps .ds sL `
49. if \*[.T]utf8 .ds sR '
50. if \*[.T]ps .ds sR '
51. ds aq \(aq
52. ds TI \(ti
53. ds ha \(ha
54. ds en \(en
55.\}
56.el \{\
57. ds aq '
58. ds TI ~
59. ds ha ^
60. ds en \(em
61.\}
62.\"
63.\" Implement .Dd with the Mdocdate RCS keyword
64.\"
65.rn Dd xD
66.de Dd
67.ie \\$1$Mdocdate: \{\
68. xD \\$2 \\$3, \\$4
69.\}
70.el .xD \\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8
71..
72.\"
73.\" .Dd must come before definition of .Mx, because when called
74.\" with -mandoc, it might implement .Mx itself, but we want to
75.\" use our own definition. And .Dd must come *first*, always.
76.\"
Elliott Hughesa3c3f962017-04-12 16:52:30 -070077.Dd $Mdocdate: April 2 2017 $
Thorsten Glaser811a5752013-07-25 14:24:45 +000078.\"
79.\" Check which macro package we use, and do other -mdoc setup.
80.\"
81.ie \n(.g \{\
82. if \*[.T]utf8 .tr \[la]\*(Lt
83. if \*[.T]utf8 .tr \[ra]\*(Gt
84. ie d volume-ds-1 .ds tT gnu
85. el .ds tT bsd
86.\}
87.el .ds tT ucb
88.\"
89.\" Implement .Mx (MirBSD)
90.\"
91.ie "\*(tT"gnu" \{\
92. eo
93. de Mx
94. nr curr-font \n[.f]
95. nr curr-size \n[.ps]
96. ds str-Mx \f[\n[curr-font]]\s[\n[curr-size]u]
97. ds str-Mx1 \*[Tn-font-size]\%MirOS\*[str-Mx]
98. if !\n[arg-limit] \
99. if \n[.$] \{\
100. ds macro-name Mx
101. parse-args \$@
102. \}
103. if (\n[arg-limit] > \n[arg-ptr]) \{\
104. nr arg-ptr +1
105. ie (\n[type\n[arg-ptr]] == 2) \
106. as str-Mx1 \~\*[arg\n[arg-ptr]]
107. el \
108. nr arg-ptr -1
109. \}
110. ds arg\n[arg-ptr] "\*[str-Mx1]
111. nr type\n[arg-ptr] 2
112. ds space\n[arg-ptr] "\*[space]
113. nr num-args (\n[arg-limit] - \n[arg-ptr])
114. nr arg-limit \n[arg-ptr]
115. if \n[num-args] \
116. parse-space-vector
117. print-recursive
118..
119. ec
120. ds sP \s0
121. ds tN \*[Tn-font-size]
122.\}
123.el \{\
124. de Mx
125. nr cF \\n(.f
126. nr cZ \\n(.s
127. ds aa \&\f\\n(cF\s\\n(cZ
128. if \\n(aC==0 \{\
129. ie \\n(.$==0 \&MirOS\\*(aa
130. el .aV \\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8 \\$9
131. \}
132. if \\n(aC>\\n(aP \{\
133. nr aP \\n(aP+1
134. ie \\n(C\\n(aP==2 \{\
135. as b1 \&MirOS\ #\&\\*(A\\n(aP\\*(aa
136. ie \\n(aC>\\n(aP \{\
137. nr aP \\n(aP+1
138. nR
139. \}
140. el .aZ
141. \}
142. el \{\
143. as b1 \&MirOS\\*(aa
144. nR
145. \}
146. \}
147..
148.\}
149.\"-
150.Dt LKSH 1
151.Os MirBSD
152.Sh NAME
153.Nm lksh
154.Nd Legacy Korn shell built on mksh
155.Sh SYNOPSIS
156.Nm
157.Bk -words
158.Op Fl +abCefhiklmnprUuvXx
159.Op Fl +o Ar opt
160.Oo
161.Fl c Ar string \*(Ba
162.Fl s \*(Ba
163.Ar file
164.Op Ar args ...
165.Oc
166.Ek
167.Sh DESCRIPTION
168.Nm
169is a command interpreter intended exclusively for running legacy
170shell scripts.
171It is built on
172.Nm mksh ;
173refer to its manual page for details on the scripting language.
174It is recommended to port scripts to
175.Nm mksh
Elliott Hughesa3c3f962017-04-12 16:52:30 -0700176instead of relying on legacy or objectionable POSIX-mandated behaviour,
Thorsten Glaser811a5752013-07-25 14:24:45 +0000177since the MirBSD Korn Shell scripting language is much more consistent.
Elliott Hughesfc0307d2016-02-02 15:26:47 -0800178.Pp
Elliott Hughesa3c3f962017-04-12 16:52:30 -0700179Do not use
180.Nm
181as an interactive or login shell; use
182.Nm mksh
183instead.
184.Pp
Elliott Hughesfc0307d2016-02-02 15:26:47 -0800185Note that it's strongly recommended to invoke
186.Nm
Elliott Hughesa3c3f962017-04-12 16:52:30 -0700187with
Elliott Hughesfc0307d2016-02-02 15:26:47 -0800188.Fl o Ic posix
Elliott Hughesfc0307d2016-02-02 15:26:47 -0800189to fully enjoy better compatibility to the
190.Tn POSIX
191standard (which is probably why you use
192.Nm
193over
194.Nm mksh
Elliott Hughesa3c3f962017-04-12 16:52:30 -0700195in the first place);
196.Fl o Ic sh
197(possibly additionally to the above) may be needed for some legacy scripts.
Thorsten Glaser811a5752013-07-25 14:24:45 +0000198.Sh LEGACY MODE
199.Nm
Elliott Hughesb27ce952015-04-21 13:39:18 -0700200currently has the following differences from
Thorsten Glaser811a5752013-07-25 14:24:45 +0000201.Nm mksh :
202.Bl -bullet
203.It
Thorsten Glaser811a5752013-07-25 14:24:45 +0000204The
205.Ev KSH_VERSION
206string identifies
207.Nm
208as
Elliott Hughes966dd552016-12-08 15:56:04 -0800209.Dq Li LEGACY KSH
Thorsten Glaser811a5752013-07-25 14:24:45 +0000210instead of
Elliott Hughes966dd552016-12-08 15:56:04 -0800211.Dq Li MIRBSD KSH .
Elliott Hughesb27ce952015-04-21 13:39:18 -0700212Note that the rest of the version string is identical between
213the two shell flavours, and the behaviour and differences can
214change between versions; see the accompanying manual page
215.Xr mksh 1
216for the versions this document applies to.
Thorsten Glaser811a5752013-07-25 14:24:45 +0000217.It
218.Nm
Thorsten Glaser811a5752013-07-25 14:24:45 +0000219uses
220.Tn POSIX
Elliott Hughes966dd552016-12-08 15:56:04 -0800221arithmetic, which has quite a few implications:
222The data type for arithmetic operations is the host
Elliott Hughesfc0307d2016-02-02 15:26:47 -0800223.Tn ISO
224C
Thorsten Glaser811a5752013-07-25 14:24:45 +0000225.Vt long
226data type.
Elliott Hughesfc0307d2016-02-02 15:26:47 -0800227Signed integer wraparound is Undefined Behaviour; this means that...
228.Bd -literal -offset indent
229$ echo $((2147483647 + 1))
230.Ed
231.Pp
232\&... is permitted to, e.g. delete all files on your system
233(the figure differs for non-32-bit systems, the rule doesn't).
Thorsten Glaser811a5752013-07-25 14:24:45 +0000234The sign of the result of a modulo operation with at least one
235negative operand is unspecified.
236Shift operations on negative numbers are unspecified.
237Division of the largest negative number by \-1 is Undefined Behaviour.
238The compiler is permitted to delete all data and crash the system
Elliott Hughesfc0307d2016-02-02 15:26:47 -0800239if Undefined Behaviour occurs (see above for an example).
Thorsten Glaser811a5752013-07-25 14:24:45 +0000240.It
241The rotation arithmetic operators are not available.
242.It
243The shift arithmetic operators take all bits of the second operand into
244account; if they exceed permitted precision, the result is unspecified.
245.It
Thorsten Glaser811a5752013-07-25 14:24:45 +0000246Unless
247.Ic set -o posix
248is active,
249.Nm
250always uses traditional mode for constructs like:
251.Bd -literal -offset indent
252$ set -- $(getopt ab:c "$@")
253$ echo $?
254.Ed
255.Pp
256POSIX mandates this to show 0, but traditional mode
257passes through the errorlevel from the
258.Xr getopt 1
259command.
260.It
Elliott Hughes96b43632015-07-17 11:39:41 -0700261Functions defined with the
262.Ic function
263reserved word share the shell options
264.Pq Ic set -o
265instead of locally scoping them.
Thorsten Glaser811a5752013-07-25 14:24:45 +0000266.El
267.Sh SEE ALSO
268.Xr mksh 1
269.Pp
Elliott Hughesa3c3f962017-04-12 16:52:30 -0700270.Pa http://www.mirbsd.org/mksh.htm
Thorsten Glaser811a5752013-07-25 14:24:45 +0000271.Pp
Elliott Hughesa3c3f962017-04-12 16:52:30 -0700272.Pa http://www.mirbsd.org/ksh\-chan.htm
Thorsten Glaser811a5752013-07-25 14:24:45 +0000273.Sh CAVEATS
274To use
275.Nm
276as
277.Pa /bin/sh ,
278compilation to enable
279.Ic set -o posix
Elliott Hughesfc0307d2016-02-02 15:26:47 -0800280by default if called as
281.Nm sh
Elliott Hughesa3c3f962017-04-12 16:52:30 -0700282.Pq adding Dv \-DMKSH_BINSHPOSIX to Dv CPPFLAGS
Elliott Hughesfc0307d2016-02-02 15:26:47 -0800283is highly recommended for better standards compliance.
Elliott Hughesa3c3f962017-04-12 16:52:30 -0700284.Pp
Elliott Hughesfc0307d2016-02-02 15:26:47 -0800285For better compatibility with legacy scripts, such as many
286.Tn Debian
287maintainer scripts, Upstart and SYSV init scripts, and other
Elliott Hughesa3c3f962017-04-12 16:52:30 -0700288unfixed scripts, also adding the
289.Dv \-DMKSH_BINSHREDUCED
290compile-time option to enable
Elliott Hughesfc0307d2016-02-02 15:26:47 -0800291.Em both
292.Ic set -o posix -o sh
293when the shell is run as
Elliott Hughesa3c3f962017-04-12 16:52:30 -0700294.Nm sh ,
295as well as integrating the optional disrecommended
296.Xr printf 1
297builtin, might be necessary.
Thorsten Glaser811a5752013-07-25 14:24:45 +0000298.Pp
299.Nm
300tries to make a cross between a legacy bourne/posix compatibl-ish
301shell and a legacy pdksh-alike but
302.Dq legacy
303is not exactly specified.
304.Pp
Thorsten Glaser811a5752013-07-25 14:24:45 +0000305Talk to the
306.Mx
307development team using the mailing list at
308.Aq miros\-mksh@mirbsd.org
309or the
310.Li \&#\&!/bin/mksh
311.Pq or Li \&#ksh
312IRC channel at
313.Pa irc.freenode.net
314.Pq Port 6697 SSL, 6667 unencrypted
315if you need any further quirks or assistance,
316and consider migrating your legacy scripts to work with
317.Nm mksh
318instead of requiring
319.Nm .