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