1.\" $MirOS: src/bin/mksh/lksh.1,v 1.26 2020/09/04 22:37:01 tg Exp $ 2.\"- 3.\" Copyright (c) 2008, 2009, 2010, 2012, 2013, 2015, 2016, 2017, 2018 4.\" mirabilos <m@mirbsd.org> 5.\" 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 for a solo en dash 29.\" * and \*(EM for a correctly spaced em dash 30.\" * <>| are problematic, so redefine and use \*(Lt\*(Gt\*(Ba 31.\" Also make sure to use \& *before* a punctuation char that is to not 32.\" be interpreted as punctuation, and especially with two-letter words 33.\" but also (after) a period that does not end a sentence (“e.g.\&”). 34.\" The section after the "doc" macropackage has been loaded contains 35.\" additional code to convene between the UCB mdoc macropackage (and 36.\" its variant as BSD mdoc in groff) and the GNU mdoc macropackage. 37.\" 38.ie \n(.g \{\ 39. if \*[.T]ascii .tr \-\N'45' 40. if \*[.T]latin1 .tr \-\N'45' 41. if \*[.T]utf8 .tr \-\N'45' 42. ds <= \[<=] 43. ds >= \[>=] 44. ds Rq \[rq] 45. ds Lq \[lq] 46. ds sL \(aq 47. ds sR \(aq 48. if \*[.T]utf8 .ds sL ` 49. if \*[.T]ps .ds sL ` 50. if \*[.T]utf8 .ds sR ' 51. if \*[.T]ps .ds sR ' 52. ds aq \(aq 53. ds TI \(ti 54. ds ha \(ha 55. ds en \(en 56.\} 57.el \{\ 58. ds aq ' 59. ds TI ~ 60. ds ha ^ 61. ds en \(em 62.\} 63.ie n \{\ 64. ds EM \ \*(en\ \& 65.\} 66.el \{\ 67. ds EM \f(TR\^\(em\^\fP 68.\} 69.\" 70.\" Implement .Dd with the Mdocdate RCS keyword 71.\" 72.rn Dd xD 73.de Dd 74.ie \\$1$Mdocdate: \{\ 75. xD \\$2 \\$3, \\$4 76.\} 77.el .xD \\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8 78.. 79.\" 80.\" .Dd must come before definition of .Mx, because when called 81.\" with -mandoc, it might implement .Mx itself, but we want to 82.\" use our own definition. And .Dd must come *first*, always. 83.\" 84.Dd $Mdocdate: September 4 2020 $ 85.\" 86.\" Check which macro package we use, and do other -mdoc setup. 87.\" 88.ie \n(.g \{\ 89. if \*[.T]utf8 .tr \[la]\*(Lt 90. if \*[.T]utf8 .tr \[ra]\*(Gt 91. ie d volume-ds-1 .ds tT gnu 92. el .ie d doc-volume-ds-1 .ds tT gnp 93. el .ds tT bsd 94.\} 95.el .ds tT ucb 96.\" 97.\" Implement .Mx (MirBSD) 98.\" 99.ie "\*(tT"gnu" \{\ 100. eo 101. de Mx 102. nr curr-font \n[.f] 103. nr curr-size \n[.ps] 104. ds str-Mx \f[\n[curr-font]]\s[\n[curr-size]u] 105. ds str-Mx1 \*[Tn-font-size]\%MirBSD\*[str-Mx] 106. if !\n[arg-limit] \ 107. if \n[.$] \{\ 108. ds macro-name Mx 109. parse-args \$@ 110. \} 111. if (\n[arg-limit] > \n[arg-ptr]) \{\ 112. nr arg-ptr +1 113. ie (\n[type\n[arg-ptr]] == 2) \ 114. as str-Mx1 \~\*[arg\n[arg-ptr]] 115. el \ 116. nr arg-ptr -1 117. \} 118. ds arg\n[arg-ptr] "\*[str-Mx1] 119. nr type\n[arg-ptr] 2 120. ds space\n[arg-ptr] "\*[space] 121. nr num-args (\n[arg-limit] - \n[arg-ptr]) 122. nr arg-limit \n[arg-ptr] 123. if \n[num-args] \ 124. parse-space-vector 125. print-recursive 126.. 127. ec 128. ds sP \s0 129. ds tN \*[Tn-font-size] 130.\} 131.el .ie "\*(tT"gnp" \{\ 132. eo 133. de Mx 134. nr doc-curr-font \n[.f] 135. nr doc-curr-size \n[.ps] 136. ds doc-str-Mx \f[\n[doc-curr-font]]\s[\n[doc-curr-size]u] 137. ds doc-str-Mx1 \*[doc-Tn-font-size]\%MirBSD\*[doc-str-Mx] 138. if !\n[doc-arg-limit] \ 139. if \n[.$] \{\ 140. ds doc-macro-name Mx 141. doc-parse-args \$@ 142. \} 143. if (\n[doc-arg-limit] > \n[doc-arg-ptr]) \{\ 144. nr doc-arg-ptr +1 145. ie (\n[doc-type\n[doc-arg-ptr]] == 2) \ 146. as doc-str-Mx1 \~\*[doc-arg\n[doc-arg-ptr]] 147. el \ 148. nr doc-arg-ptr -1 149. \} 150. ds doc-arg\n[doc-arg-ptr] "\*[doc-str-Mx1] 151. nr doc-type\n[doc-arg-ptr] 2 152. ds doc-space\n[doc-arg-ptr] "\*[doc-space] 153. nr doc-num-args (\n[doc-arg-limit] - \n[doc-arg-ptr]) 154. nr doc-arg-limit \n[doc-arg-ptr] 155. if \n[doc-num-args] \ 156. doc-parse-space-vector 157. doc-print-recursive 158.. 159. ec 160. ds sP \s0 161. ds tN \*[doc-Tn-font-size] 162.\} 163.el \{\ 164. de Mx 165. nr cF \\n(.f 166. nr cZ \\n(.s 167. ds aa \&\f\\n(cF\s\\n(cZ 168. if \\n(aC==0 \{\ 169. ie \\n(.$==0 \&MirBSD\\*(aa 170. el .aV \\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8 \\$9 171. \} 172. if \\n(aC>\\n(aP \{\ 173. nr aP \\n(aP+1 174. ie \\n(C\\n(aP==2 \{\ 175. as b1 \&MirBSD\ #\&\\*(A\\n(aP\\*(aa 176. ie \\n(aC>\\n(aP \{\ 177. nr aP \\n(aP+1 178. nR 179. \} 180. el .aZ 181. \} 182. el \{\ 183. as b1 \&MirBSD\\*(aa 184. nR 185. \} 186. \} 187.. 188.\} 189.\"- 190.Dt LKSH 1 191.Os MirBSD 192.Sh NAME 193.Nm lksh 194.Nd Legacy Korn shell built on mksh 195.Sh SYNOPSIS 196.Nm 197.Bk -words 198.Op Fl +abCefhiklmnprUuvXx 199.Op Fl +o Ar opt 200.Oo 201.Fl c Ar string \*(Ba 202.Fl s \*(Ba 203.Ar file 204.Op Ar args ... 205.Oc 206.Ek 207.Sh DESCRIPTION 208.Nm 209is a command interpreter intended exclusively for running legacy 210shell scripts. 211It is built on 212.Nm mksh ; 213refer to its manual page for details on the scripting language. 214It is recommended to port scripts to 215.Nm mksh 216instead of relying on legacy or objectionable POSIX-mandated behaviour, 217since the MirBSD Korn Shell scripting language is much more consistent. 218.Pp 219Do not use 220.Nm 221as an interactive or login shell; use 222.Nm mksh 223instead. 224.Pp 225Note that it's strongly recommended to invoke 226.Nm 227with 228.Fl o Ic posix 229to fully enjoy better compatibility to the 230.Tn POSIX 231standard (which is probably why you use 232.Nm 233over 234.Nm mksh 235in the first place); 236.Fl o Ic sh 237(possibly additionally to the above) may be needed for some legacy scripts. 238.Sh LEGACY MODE 239.Nm 240currently has the following differences from 241.Nm mksh : 242.Bl -bullet 243.It 244The 245.Ev KSH_VERSION 246string identifies 247.Nm 248as 249.Dq Li LEGACY KSH 250instead of 251.Dq Li MIRBSD KSH . 252Note that the rest of the version string is identical between 253the two shell flavours, and the behaviour and differences can 254change between versions; see the accompanying manual page 255.Xr mksh 1 256for the versions this document applies to. 257.It 258.Nm 259uses 260.Tn POSIX 261arithmetic, which has quite a few implications: 262The data type for arithmetic operations is the host 263.Tn ISO 264C 265.Vt long 266data type. 267Signed integer wraparound is Undefined Behaviour; this means that... 268.Bd -literal -offset indent 269$ echo $((2147483647 + 1)) 270.Ed 271.Pp 272\&... is permitted to, e.g. delete all files on your system 273(the figure differs for non-32-bit systems, the rule doesn't). 274The sign of the result of a modulo operation with at least one 275negative operand is unspecified. 276Shift operations on negative numbers are unspecified. 277Division of the largest negative number by \-1 is Undefined Behaviour. 278The compiler is permitted to delete all data and crash the system 279if Undefined Behaviour occurs (see above for an example). 280.It 281The rotation arithmetic operators are not available. 282.It 283The shift arithmetic operators take all bits of the second operand into 284account; if they exceed permitted precision, the result is unspecified. 285.It 286Unless 287.Ic set -o posix 288is active, 289.Nm 290always uses traditional mode for constructs like: 291.Bd -literal -offset indent 292$ set -- $(getopt ab:c "$@") 293$ echo $? 294.Ed 295.Pp 296POSIX mandates this to show 0, but traditional mode 297passes through the errorlevel from the 298.Xr getopt 1 299command. 300.It 301Functions defined with the 302.Ic function 303reserved word share the shell options 304.Pq Ic set -o 305instead of locally scoping them. 306.El 307.Sh SEE ALSO 308.Xr mksh 1 309.Pp 310.Pa http://www.mirbsd.org/mksh.htm 311.Pp 312.Pa http://www.mirbsd.org/ksh\-chan.htm 313.Sh CAVEATS 314To use 315.Nm 316as 317.Pa /bin/sh , 318compilation to enable 319.Ic set -o posix 320by default if called as 321.Nm sh 322.Pq adding Dv \-DMKSH_BINSHPOSIX to Dv CPPFLAGS 323is highly recommended for better standards compliance. 324.Pp 325For better compatibility with legacy scripts, such as many 326.Tn Debian 327maintainer scripts, Upstart and SYSV init scripts, and other 328unfixed scripts, also adding the 329.Dv \-DMKSH_BINSHREDUCED 330compile-time option to enable 331.Em both 332.Ic set -o posix -o sh 333when the shell is run as 334.Nm sh , 335as well as integrating the optional disrecommended 336.Xr printf 1 337builtin, might be necessary. 338.Pp 339.Nm 340tries to make a cross between a legacy bourne/posix compatibl-ish 341shell and a legacy pdksh-alike but 342.Dq legacy 343is not exactly specified. 344.Pp 345Talk to the 346.Mx 347development team and users using the mailing list at 348.Aq Mt miros\-mksh@mirbsd.org 349(please note the EU-DSGVO/GDPR notice on 350.Pa http://www.mirbsd.org/rss.htm#lists 351and in the SMTP banner!) or the 352.Li \&#\&!/bin/mksh 353.Pq or Li \&#ksh 354IRC channel at 355.Pa irc.freenode.net 356.Pq Port 6697 SSL, 6667 unencrypted 357if you need any further quirks or assistance, 358and consider migrating your legacy scripts to work with 359.Nm mksh 360instead of requiring 361.Nm . 362