-.\" $MirOS: src/bin/mksh/mksh.1,v 1.336 2014/06/24 20:47:44 tg Exp $
-.\" $OpenBSD: ksh.1,v 1.152 2014/02/12 16:28:13 schwarze Exp $
+.\" $MirOS: src/bin/mksh/mksh.1,v 1.413 2016/08/10 18:20:05 tg Exp $
+.\" $OpenBSD: ksh.1,v 1.160 2015/07/04 13:27:04 feinerer Exp $
.\"-
.\" Copyright © 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
-.\" 2010, 2011, 2012, 2013, 2014
-.\" Thorsten Glaser <tg@mirbsd.org>
+.\" 2010, 2011, 2012, 2013, 2014, 2015, 2016
+.\" mirabilos <m@mirbsd.org>
.\"
.\" Provided that these terms and disclaimer and all copyright notices
.\" are retained or reproduced in an accompanying document, permission
.\" * ^ 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
-.\" Also make sure to use \& especially with two-letter words.
+.\" 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.\&”).
.\" 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.
.\" with -mandoc, it might implement .Mx itself, but we want to
.\" use our own definition. And .Dd must come *first*, always.
.\"
-.Dd $Mdocdate: June 24 2014 $
+.Dd $Mdocdate: August 10 2016 $
.\"
.\" Check which macro package we use, and do other -mdoc setup.
.\"
Its command language is a superset of the
.Xr sh C
shell language and largely compatible to the original Korn shell.
+At times, this manual page may give scripting advice; while it
+sometimes does take portable shell scripting or various standards
+into account all information is first and foremost presented with
+.Nm
+in mind and should be taken as such.
.Ss I'm an Android user, so what's mksh?
.Nm mksh
is a
.Ar string .
.It Fl i
Interactive shell.
-A shell is
+A shell that reads commands from standard input is
.Dq interactive
if this
option is used or if both standard input and standard error are attached
.Ql \&(( .. ))
is used in arithmetic expressions;
and lastly,
-.Ql \&( .. )\&
+.Ql \&( .. \&)
is used to create subshells.
.Pp
Whitespace and meta-characters can be quoted individually using a backslash
or in groups using double
.Pq Sq \&"
or single
-.Pq Sq \*(aq
+.Pq Dq \*(aq
quotes.
Note that the following characters are also treated specially by the
shell and must be quoted if they are to represent themselves:
.Ql }
delimit
.Xr csh 1 Ns -style
-alterations (see
+alternations (see
.Sx Brace expansion
below);
and finally,
.It Xo case Ar word No in
.Oo Op \&(
.Ar pattern
-.Op \*(Ba Ar pat
+.Op \*(Ba Ar pattern
.No ... Ns )
.Ar list
-.Op ;; \*(Ba ;&\& \*(Ba ;\*(Ba\ \&
-.Oc ... esac
+.Ic terminator
+.Oc No ... esac
.Xc
The
.Ic case
and
.Ic esac
e.g.\&
-.Ic case $foo { *) echo bar;; } .
+.Ic case $foo { *) echo bar ;; } .
.Pp
-The list terminators are:
+The list
+.Ic terminator Ns s
+are:
.Bl -tag -width 4n
.It Ql ;;
Terminate after the list.
.Sx Arithmetic expressions
and the
.Ic let
-command, below).
+command, below) in a compound construct.
.It Bq Bq Ar \ \&expression\ \&
Similar to the
.Ic test
.Ql \e
and the newline are stripped.
Second, a single quote
-.Pq Sq \*(aq
+.Pq Dq \*(aq
quotes everything up to the next single quote (this may span lines).
Third, a double quote
.Pq Sq \&"
quotes all characters, except
.Ql $ ,
-.Ql \`
-and
.Ql \e ,
-up to the next unquoted double quote.
+and
+.Ql \` ,
+up to the next unescaped double quote.
.Ql $
and
.Ql \`
-inside double quotes have their usual meaning (i.e. parameter, command, or
-arithmetic substitution) except no field splitting is carried out on the
-results of double-quoted substitutions.
+inside double quotes have their usual meaning (i.e. parameter, arithmetic,
+or command substitution) except no field splitting is carried out on the
+results of double-quoted substitutions, and the old-style form of command
+substitution has backslash-quoting for double quotes enabled.
If a
.Ql \e
inside a double-quoted string is followed by
-.Ql \e ,
+.Ql \&" ,
.Ql $ ,
-.Ql \` ,
+.Ql \e ,
or
-.Ql \&" ,
-it is replaced by the second character; if it is followed by a newline, both
-the
+.Ql \` ,
+only the
+.Ql \e
+is removed, i.e. the combination is replaced by the second character;
+if it is followed by a newline, both the
.Ql \e
and the newline are stripped; otherwise, both the
.Ql \e
the expanded result is treated as any other single-quoted string.
If a double-quoted string is preceded by an unquoted
.Ql $ ,
-the latter is ignored.
+the
+.Ql $
+is simply ignored.
.Ss Backslash expansion
In places where backslashes are expanded, certain C and
.At
.Pp
The following command aliases are defined automatically by the shell:
.Bd -literal -offset indent
-autoload=\*(aqtypeset \-fu\*(aq
-functions=\*(aqtypeset \-f\*(aq
-hash=\*(aqalias \-t\*(aq
-history=\*(aqfc \-l\*(aq
-integer=\*(aqtypeset \-i\*(aq
-local=\*(aqtypeset\*(aq
-login=\*(aqexec login\*(aq
-nameref=\*(aqtypeset \-n\*(aq
+autoload=\*(aq\etypeset \-fu\*(aq
+functions=\*(aq\etypeset \-f\*(aq
+hash=\*(aq\ebuiltin alias \-t\*(aq
+history=\*(aq\ebuiltin fc \-l\*(aq
+integer=\*(aq\etypeset \-i\*(aq
+local=\*(aq\etypeset\*(aq
+login=\*(aq\eexec login\*(aq
+nameref=\*(aq\etypeset \-n\*(aq
nohup=\*(aqnohup \*(aq
-r=\*(aqfc \-e \-\*(aq
-stop=\*(aqkill \-STOP\*(aq
-type=\*(aqwhence \-v\*(aq
+r=\*(aq\ebuiltin fc \-e \-\*(aq
+type=\*(aq\ebuiltin whence \-v\*(aq
.Ed
.Pp
Tracked aliases allow the shell to remember where it found a particular
time the command is executed, the shell checks the saved path to see that it
is still valid, and if so, avoids repeating the path search.
Tracked aliases can be listed and created using
-.Ic alias \-t .
+.Ic alias Fl t .
Note that changing the
.Ev PATH
parameter clears the saved paths for all tracked aliases.
If the
.Ic trackall
option is set (i.e.\&
-.Ic set \-o Ic trackall
+.Ic set Fl o Ic trackall
or
-.Ic set \-h ) ,
+.Ic set Fl h ) ,
the shell tracks all commands.
This option is set automatically for non-interactive shells.
For interactive shells, only the following commands are
.Ic return
work, and in that
.Ic exit
-terminates the parent shell.
+terminates the parent shell; shell options are shared.
.Pp
Another variant of substitution are the valsubs (value substitutions)
.Pf ${\*(Ba\& Ns Ar command Ns \&;}
the, initially empty, expression-local variable
.Ev REPLY
is set to within the
-.Ar command Ns No s .
+.Ar command Ns s .
.Pp
If a substitution appears outside of double quotes, the results of the
substitution are generally subject to word or field splitting according to
whitespace octets, delimit a field.
As a special case, leading and trailing
.Ev IFS
-whitespace and trailing
-.Ev IFS
-non-whitespace are stripped (i.e. no leading or trailing empty field
-is created by it); leading
+whitespace is stripped (i.e. no leading or trailing empty field
+is created by it); leading or trailing
.Pf non- Ev IFS
whitespace does create an empty field.
.Pp
.Sq D .
Note that if the
.Ev IFS
-parameter is set to the
-.Dv NULL
-string, no field splitting is done; if the parameter is unset, the default
-value of space, tab, and newline is used.
+parameter is set to the empty string, no field splitting is done;
+if it is unset, the default value of space, tab, and newline is used.
.Pp
Also, note that the field splitting applies only to the immediate result of
the substitution.
For
.Pf $( Ns Ar command Ns \&)
and
+.Pf ${\*(Ba\& Ns Ar command Ns \&;}
+and
.Pf ${\ \& Ar command Ns \&;}
substitutions, normal quoting rules are used when
.Ar command
.Ql \` ,
or
.Ql \e
-is stripped (a
+is stripped (as is
+.Ql \&"
+when the substitution is part of a double-quoted string); a backslash
.Ql \e
-followed by any other character is unchanged).
+followed by any other character is unchanged.
As a special case in command substitutions, a command of the form
.Pf \*(Lt Ar file
is interpreted to mean substitute the contents of
.Ic getopts ,
.Ic read ,
and
-.Ic set \-A
+.Ic set Fl A
commands.
Lastly, parameters can be assigned values using assignment operators
inside arithmetic expressions (see
.Pp
The following forms of parameter substitution can also be used (if
.Ar name
-is an array, its element #0 will be substituted in a scalar context):
+is an array, the element with the key
+.Dq 0
+will be substituted in scalar context):
.Pp
.Bl -tag -width Ds -compact
.It Pf ${# Ns Ar name Ns \&}
.Ic nameref
command (which is an alias for
.Ic typeset Fl n ) .
+.Ar name
+cannot be one of most special parameters (see below).
.Pp
.It Pf ${! Ns Ar name Ns \&[*]}
.It Pf ${! Ns Ar name Ns \&[@]}
.Xc
.It Xo
.Pf ${ Ar name
+.Pf /# Ar pattern / Ar string No }
+.Xc
+.It Xo
+.Pf ${ Ar name
+.Pf /% Ar pattern / Ar string No }
+.Xc
+.It Xo
+.Pf ${ Ar name
.Pf // Ar pattern / Ar string No }
.Xc
.Sm on
-Like ${..#..} substitution, but it replaces the longest match of
-.Ar pattern ,
-anchored anywhere in the value, with
-.Ar string .
-If
+The longest match of
.Ar pattern
-begins with
-.Ql # ,
-it is anchored at the beginning of the value; if it begins with
-.Ql % ,
-it is anchored at the end.
-Patterns that are empty or consist only of wildcards are invalid.
-A single
-.Ql /
-replaces the first occurence of the search
-.Ar pattern ,
-and two of them replace all occurences.
-If
-.Pf / Ar string
-is omitted, the
+in the value of parameter
+.Ar name
+is replaced with
+.Ar string
+(deleted if
+.Ar string
+is empty; the trailing slash
+.Pq Ql /
+may be omitted in that case).
+A leading slash followed by
+.Ql #
+or
+.Ql %
+causes the pattern to be anchored at the beginning or end of
+the value, respectively; empty unanchored
+.Ar pattern Ns s
+cause no replacement; a single leading slash or use of a
.Ar pattern
-is replaced by the empty string, i.e. deleted.
+that matches the empty string causes the replacement to
+happen only once; two leading slashes cause all occurrences
+of matches in the value to be replaced.
Cannot be applied to a vector.
Inefficiently implemented, may be slow.
.Pp
.Sm off
.It Xo
+.Pf ${ Ar name
+.Pf @/ Ar pattern / Ar string No }
+.Xc
+.Sm on
+The same as
+.Sm off
+.Xo
+.Pf ${ Ar name
+.Pf // Ar pattern / Ar string No } ,
+.Xc
+.Sm on
+except that both
+.Ar pattern
+and
+.Ar string
+are expanded anew for each iteration.
+.Pp
+.Sm off
+.It Xo
.Pf ${ Ar name : Ns Ar pos
.Pf : Ns Ar len Ns }
.Xc
The exit status of the last non-asynchronous command executed.
If the last command was killed by a signal,
.Ic $?\&
-is set to 128 plus the signal number.
+is set to 128 plus the signal number, but at most 255.
.It Ev 0
The name of the shell, determined as follows:
the first argument to
.It Ev BASHPID
The PID of the shell or subshell.
.It Ev CDPATH
-Search path for the
+Like
+.Ev PATH ,
+but used to resolve the argument to the
.Ic cd
built-in command.
-It works the same way as
-.Ev PATH
-for those directories not beginning with
-.Ql /
-in
-.Ic cd
-commands.
Note that if
.Ev CDPATH
is set and does not contain
.Sq \&.
-or contains an empty path, the current directory is not searched.
+or an empty string element, the current directory is not searched.
Also, the
.Ic cd
built-in command will display the resulting directory when a match is found
.Ev LINES .
This parameter is used by the interactive line editing modes, and by the
.Ic select ,
-.Ic set \-o ,
+.Ic set Fl o ,
and
-.Ic kill \-l
+.Ic kill Fl l
commands to format information columns.
Importing from the environment or unsetting this parameter removes the
binding to the actual terminal size in favour of the provided value.
If this parameter is found to be set after any profile files are executed, the
expanded value is used as a shell startup file.
It typically contains function and alias definitions.
-.It Ev ERRNO
-Integer value of the shell's
-.Va errno
-variable.
-It indicates the reason the last system call failed.
-Not yet implemented.
+.It Ev EPOCHREALTIME
+Time since the epoch, as returned by
+.Xr gettimeofday 2 ,
+formatted as decimal
+.Va tv_sec
+followed by a dot
+.Pq Sq \&.
+and
+.Va tv_usec
+padded to exactly six decimal digits.
.It Ev EXECSHELL
If set, this parameter is assumed to contain the shell that is to be used to
execute commands that
below for more information.
.It Ev HISTFILE
The name of the file used to store command history.
-When assigned to, history is loaded from the specified file.
+When assigned to or unset, the file is opened, history is truncated
+then loaded from the file; subsequent new commands (possibly consisting
+of several lines) are appended once they successfully compiled.
Also, several invocations of the shell will share history if their
.Ev HISTFILE
parameters all point to the same file.
.Sy Note :
If
.Ev HISTFILE
-isn't set, no history file is used.
+is unset or empty, no history file is used.
This is different from
.At
.Nm ksh .
.It Ev HISTSIZE
The number of commands normally stored for history.
The default is 2047.
+Do not set this value to insanely high values such as 1000000000 because
+.Nm
+can then not allocate enough memory for the history and will not start.
.It Ev HOME
The default directory for the
.Ic cd
The real group id of the shell.
.It Ev KSHUID
The real user id of the shell.
+.It Ev KSH_MATCH
+The last matched string.
+In a future version, this will be an indexed array,
+with indexes 1 and up capturing matching groups.
+Set by string comparisons (== and !=) in double-bracket test
+expressions when a match is found (when != returns false), by
+.Ic case
+when a match is encountered, and by the substitution operations
+.Sm off
+.Xo
+.Pf ${ Ar x
+.Pf # Ar pat No } ,
+.Sm on
+.Xc
+.Sm off
+.Xo
+.Pf ${ Ar x
+.Pf ## Ar pat No } ,
+.Sm on
+.Xc
+.Sm off
+.Xo
+.Pf ${ Ar x
+.Pf % Ar pat No } ,
+.Sm on
+.Xc
+.Sm off
+.Xo
+.Pf ${ Ar x
+.Pf %% Ar pat No } ,
+.Sm on
+.Xc
+.Sm off
+.Xo
+.Pf ${ Ar x
+.Pf / Ar pat / Ar rpl No } ,
+.Sm on
+.Xc
+.Sm off
+.Xo
+.Pf ${ Ar x
+.Pf /# Ar pat / Ar rpl No } ,
+.Sm on
+.Xc
+.Sm off
+.Xo
+.Pf ${ Ar x
+.Pf /% Ar pat / Ar rpl No } ,
+.Sm on
+.Xc
+.Sm off
+.Xo
+.Pf ${ Ar x
+.Pf // Ar pat / Ar rpl No } ,
+.Sm on
+.Xc
+and
+.Sm off
+.Xo
+.Pf ${ Ar x
+.Pf @/ Ar pat / Ar rpl No } .
+.Sm on
+.Xc
+See the end of the Emacs editing mode documentation for an example.
.It Ev KSH_VERSION
The name and version of the shell (read-only).
See also the version commands in
Always set, defaults to 24.
See
.Ev COLUMNS .
-.It Ev EPOCHREALTIME
-Time since the epoch, as returned by
-.Xr gettimeofday 2 ,
-formatted as decimal
-.Va tv_sec
-followed by a dot
-.Pq Sq .\&
-and
-.Va tv_usec
-padded to exactly six decimal digits.
.It Ev OLDPWD
The previous working directory.
Unset if
.Ic getopts
to process arguments from the beginning the next time it is invoked.
.It Ev PATH
-A colon separated list of directories that are searched when looking for
-commands and files sourced using the
+A colon (semicolon on OS/2) separated list of directories that are
+searched when looking for commands and files sourced using the
.Sq \&.
command (see below).
An empty string resulting from a leading or trailing
sequences (such as escape codes) by prefixing your prompt with a
character (such as Ctrl-A) followed by a carriage return and then delimiting
the escape codes with this character.
-Any occurences of that character in the prompt are not printed.
+Any occurrences of that character in the prompt are not printed.
By the way, don't blame me for
this hack; it's derived from the original
.Xr ksh88 1 ,
.Ql + ,
or
.Ql \- ,
-the value of the
+the simplified value of the
.Ev HOME ,
.Ev PWD ,
or
.Pp
The home directory of previously expanded login names are cached and re-used.
The
-.Ic alias \-d
+.Ic alias Fl d
command may be used to list, change, and add to this cache (e.g.\&
.Ic alias \-d fac=/usr/local/facilities; cd \*(TIfac/bin ) .
-.Ss Brace expansion (alteration)
+.Ss Brace expansion (alternation)
Brace expressions take the following form:
.Bd -unfilled -offset indent
.Sm off
.Pa /dev/null ,
and commands for which any of the following redirections have been specified:
.Bl -tag -width XXxxmarker
-.It \*(Gt Ar file
+.It \*(Gt Ns Ar file
Standard output is redirected to
.Ar file .
If
.Ar cmd
gets a chance to actually read
.Ar foo .
-.It \*(Gt\*(Ba Ar file
+.It \*(Gt\*(Ba Ns Ar file
Same as
.Ic \*(Gt ,
except the file is truncated, even if the
.Ic noclobber
option is set.
-.It \*(Gt\*(Gt Ar file
+.It \*(Gt\*(Gt Ns Ar file
Same as
.Ic \*(Gt ,
except if
Also, the file is opened
in append mode, so writes always go to the end of the file (see
.Xr open 2 ) .
-.It \*(Lt Ar file
+.It \*(Lt Ns Ar file
Standard input is redirected from
.Ar file ,
which is opened for reading.
-.It \*(Lt\*(Gt Ar file
+.It \*(Lt\*(Gt Ns Ar file
Same as
.Ic \*(Lt ,
except the file is opened for reading and writing.
-.It \*(Lt\*(Lt Ar marker
+.It \*(Lt\*(Lt Ns Ar marker
After reading the command line containing this kind of redirection (called a
.Dq here document ) ,
the shell copies lines from the command source into a temporary file until a
.Sq \&""
quotes with nothing in between, the here document ends at the next empty line
and substitution will not be performed.
-.It \*(Lt\*(Lt\- Ar marker
+.It \*(Lt\*(Lt\- Ns Ar marker
Same as
.Ic \*(Lt\*(Lt ,
except leading tabs are stripped from lines in the here document.
-.It \*(Lt\*(Lt\*(Lt Ar word
+.It \*(Lt\*(Lt\*(Lt Ns Ar word
Same as
.Ic \*(Lt\*(Lt ,
except that
.Em is
the here document.
This is called a here string.
-.It \*(Lt& Ar fd
+.It \*(Lt& Ns Ar fd
Standard input is duplicated from file descriptor
.Ar fd .
.Ar fd
-can be a number, indicating the number of an existing file descriptor;
+can be a single digit, indicating the number of an existing file descriptor;
the letter
.Ql p ,
indicating the file descriptor associated with the output of the current
co-process; or the character
.Ql \- ,
indicating standard input is to be closed.
-Note that
-.Ar fd
-is limited to a single digit in most shell implementations.
-.It \*(Gt& Ar fd
+.It \*(Gt& Ns Ar fd
Same as
.Ic \*(Lt& ,
except the operation is done on standard output.
-.It &\*(Gt Ar file
+.It &\*(Gt Ns Ar file
Same as
-.Ic \*(Gt Ar file 2\*(Gt&1 .
-This is a GNU
+.Ic \*(Gt Ns Ar file 2\*(Gt&1 .
+This is a deprecated (legacy) GNU
.Nm bash
extension supported by
.Nm
-which also supports the preceding explicit fd number, for example,
-.Ic 3&\*(Gt Ar file
+which also supports the preceding explicit fd digit, for example,
+.Ic 3&\*(Gt Ns Ar file
is the same as
-.Ic 3\*(Gt Ar file 2\*(Gt&3
+.Ic 3\*(Gt Ns Ar file 2\*(Gt&3
in
.Nm
but a syntax error in GNU
.Nm bash .
-Setting the
-.Fl o Ar posix
-or
-.Fl o Ar sh
-shell options disable parsing of this redirection;
-it's a compatibility feature to legacy scripts, to
-not be used when writing new shell code.
.It Xo
-.No &\*(Gt\*(Ba Ar file ,
-.No &\*(Gt\*(Gt Ar file ,
-.No &\*(Gt& Ar fd
+.No &\*(Gt\*(Ba Ns Ar file ,
+.No &\*(Gt\*(Gt Ns Ar file ,
+.No &\*(Gt& Ns Ar fd
.Xc
Same as
-.Ic \*(Gt\*(Ba Ar file ,
-.Ic \*(Gt\*(Gt Ar file ,
+.Ic \*(Gt\*(Ba Ns Ar file ,
+.Ic \*(Gt\*(Gt Ns Ar file ,
or
-.Ic \*(Gt& Ar fd ,
+.Ic \*(Gt& Ns Ar fd ,
followed by
.Ic 2\*(Gt&1 ,
as above.
In any of the above redirections, the file descriptor that is redirected
(i.e. standard input or standard output)
can be explicitly given by preceding the
-redirection with a number (portably, only a single digit).
+redirection with a single digit.
Parameter, command, and arithmetic
substitutions, tilde substitutions, and (if the shell is interactive)
file name generation are all performed on the
.Pp
.D1 $ cat /foo/bar 2\*(Gt&1 \*(Gt/dev/null \*(Ba pr \-n \-t
.Pp
-File descriptors created by input/output redirections are private to the
-Korn shell, but passed to sub-processes if
-.Fl o Ic posix
-or
-.Fl o Ic sh
-is set.
+File descriptors created by I/O redirections are private to the shell.
.Ss Arithmetic expressions
Integer arithmetic expressions can be used with the
.Ic let
as numeric arguments to the
.Ic test
command, and as the value of an assignment to an integer parameter.
+.Em Warning :
+This also affects implicit conversion to integer, for example as done by the
+.Ic let
+command.
+.Em Never
+use unchecked user input, e.g. from the environment, in arithmetics!
.Pp
Expressions are calculated using signed arithmetic and the
.Vt mksh_ari_t
Binary operators:
.Bd -literal -offset indent
,
-= += \-= *= /= %= \*(Lt\*(Lt\*(Lt= \*(Gt\*(Gt\*(Gt= \*(Lt\*(Lt= \*(Gt\*(Gt= &= \*(ha= \*(Ba=
+= += \-= *= /= %= \*(Lt\*(Lt= \*(Gt\*(Gt= \*(ha\*(Lt= \*(ha\*(Gt= &= \*(ha= \*(Ba=
\*(Ba\*(Ba
&&
\*(Ba
&
== !=
\*(Lt \*(Lt= \*(Gt \*(Gt=
-\*(Lt\*(Lt\*(Lt \*(Gt\*(Gt\*(Gt \*(Lt\*(Lt \*(Gt\*(Gt
+\*(Lt\*(Lt \*(Gt\*(Gt \*(ha\*(Lt \*(ha\*(Gt
+ \-
* / %
.Ed
.Ar base Ns # Ns Ar number ,
where
.Ar base
-is a decimal integer specifying the base, and
+is a decimal integer specifying the base (up to 36), and
.Ar number
is a number in the specified base.
Additionally, base-16 integers may be specified by prefixing them with
.Pq case-insensitive
in all forms of arithmetic expressions, except as numeric arguments to the
.Ic test
-built-in command.
+built-in utility.
Prefixing numbers with a sole digit zero
.Pq Sq 0
-leads to the shell interpreting it as base-8 (octal) integer in
-.Ic posix
-mode
-.Em only ;
-historically, (pd)ksh has never done so either anyway,
-and it's unsafe to do that, but POSIX demands it nowadays.
+does not cause interpretation as octal (except in POSIX mode,
+as required by the standard), as that's unsafe to do.
+.Pp
As a special
.Nm mksh
extension, numbers to the base of one are treated as either (8-bit
behaviour is undefined (usually, the shell aborts with a parse error,
but rarely, it succeeds, e.g. on the sequence C2 20).
That's why you should always use ASCII mode unless you know that the
-input is well-formed UTF-8 in the range of 0000..FFFD.
+input is well-formed UTF-8 in the range of 0000..FFFD if you use this
+feature, as opposed to
+.Ic read Fl a .
.Pp
The operators are evaluated as follows:
.Bl -tag -width Ds -offset indent
.It =
Assignment; the variable on the left is set to the value on the right.
.It Xo
-.No += \-= *= /= %= \*(Lt\*(Lt\*(Lt= \*(Gt\*(Gt\*(Gt=
-.No \*(Lt\*(Lt= \*(Gt\*(Gt= &= \*(ha= \*(Ba=
+.No += \-= *= /= %= \*(Lt\*(Lt= \*(Gt\*(Gt=
+.No \*(ha\*(Lt= \*(ha\*(Gt= &= \*(ha= \*(Ba=
.Xc
Assignment operators.
.Sm off
Less than; the result is 1 if the left argument is less than the right, 0 if
not.
.It \*(Lt= \*(Gt \*(Gt=
-Less than or equal, greater than or equal, greater than.
+Less than or equal, greater than, greater than or equal.
See
.Ic \*(Lt .
-.It \*(Lt\*(Lt\*(Lt \*(Gt\*(Gt\*(Gt
-Rotate left (right); the result is similar to shift (see
-.Ic \*(Lt\*(Lt )
+.It \*(Lt\*(Lt \*(Gt\*(Gt
+Shift left (right); the result is the left argument with its bits
+arithmetically (signed operation) or logically (unsigned expression)
+shifted left (right) by the amount given in the right argument.
+.It \*(ha\*(Lt \*(ha\*(Gt
+Rotate left (right); the result is similar to shift,
except that the bits shifted out at one end are shifted in
at the other end, instead of zero or sign bits.
-.It \*(Lt\*(Lt \*(Gt\*(Gt
-Shift left (right); the result is the left argument with its bits shifted left
-(right) by the amount given in the right argument.
.It + \- * /
Addition, subtraction, multiplication, and division.
.It %
-Remainder; the result is the remainder of the division of the left argument by
-the right.
+Remainder; the result is the symmetric remainder of the division of the left
+argument by the right.
+To get the mathematical modulus of
+.Dq a Ic mod No b ,
+use the formula
+.Do
+.Pq a % b + b
+.No % b
+.Dc .
.It Xo
.Sm off
.Aq Ar arg1 ?
A co-process (which is a pipeline created with the
.Sq \*(Ba&
operator) is an asynchronous process that the shell can both write to (using
-.Ic print \-p )
+.Ic print Fl p )
and read from (using
-.Ic read \-p ) .
+.Ic read Fl p ) .
The input and output of the co-process can also be manipulated using
.Ic \*(Gt&p
and
portion of the co-process output when the most recently started co-process
(instead of when all sharing co-processes) exits.
.It
-.Ic print \-p
+.Ic print Fl p
will ignore
.Dv SIGPIPE
signals during writes if the signal is not being trapped or ignored; the same
is true if the co-process input has been duplicated to another file descriptor
and
-.Ic print \-u Ns Ar n
+.Ic print Fl u Ns Ar n
is used.
.El
.Ss Functions
A list of functions can be obtained using
.Ic typeset +f
and the function definitions can be listed using
-.Ic typeset \-f .
+.Ic typeset Fl f .
The
.Ic autoload
command (which is an alias for
-.Ic typeset \-fu )
+.Ic typeset Fl fu )
may be used to create undefined functions: when an undefined function is
executed, the shell searches the path specified in the
.Ev FPATH
and
.Dq export ,
which can be set with
-.Ic typeset \-ft
+.Ic typeset Fl ft
and
-.Ic typeset \-fx ,
+.Ic typeset Fl fx ,
respectively.
When a traced function is executed, the shell's
.Ic xtrace
.Ic getopts
outside the function).
.It
-Bourne-style function definitions take precedence over alias dereferences
-and remove alias definitions upon encounter, while aliases take precedence
-over Korn-style functions.
+Shell options
+.Pq Ic set Fl o
+have local scope, i.e. changes inside a function are reset upon its exit.
.El
.Pp
In the future, the following differences may also be added:
.Nm
commands keeping assignments:
.Pp
-.Ic builtin , global , typeset , wait
+.Ic builtin , global , source , typeset ,
+.Ic wait
.Pp
Builtins that are not special:
.Pp
.Ic [ , alias , bg , bind ,
.Ic cat , cd , command , echo ,
.Ic false , fc , fg , getopts ,
-.Ic jobs , kill , let , mknod ,
-.Ic print , pwd , read , realpath ,
-.Ic rename , sleep , suspend , test ,
-.Ic true , ulimit , umask , unalias ,
-.Ic whence
+.Ic jobs , kill , let , print ,
+.Ic pwd , read , realpath , rename ,
+.Ic sleep , suspend , test , true ,
+.Ic ulimit , umask , unalias , whence
.Pp
Once the type of command has been determined, any command-line parameter
assignments are performed and exported for the duration of the command.
.Pp
-The following describes the special and regular built-in commands:
+The following describes the special and regular built-in commands and
+builtin-like reserved words:
.Pp
.Bl -tag -width false -compact
.It Ic \&. Ar file Op Ar arg ...
.Ar string ,
which should consist of a control character
optionally preceded by one of the two prefix characters
-and optionally succeded by a tilde character.
+and optionally succeeded by a tilde character.
Future input of the
.Ar string
will cause the editing command to be immediately invoked.
is a single dash
.Pq Sq -
or absent, read from standard input.
-Unless compiled with
-.Dv MKSH_NO_EXTERNAL_CAT ,
-if any options are given, an external
-.Xr cat 1
-utility is invoked instead if called from the shell.
For direct builtin calls, the
.Tn POSIX
.Fl u
option is supported as a no-op.
+For calls from shell, if any options are given, an external
+.Xr cat 1
+utility is preferred over the builtin.
.Pp
.It Xo
.Ic cd
.Ar cmd ,
information about what would be executed is given (and the same is done for
.Ar arg ... ) .
-For special and regular built-in commands and functions, their names are simply
-printed; for aliases, a command that defines them is printed; and for commands
-found by searching the
+For builtins, functions and keywords, their names are simply printed;
+for aliases, a command that defines them is printed;
+for utilities found by searching the
.Ev PATH
parameter, the full path of the command is printed.
If no command is found
.Pp
.It Xo
.Ic exec
+.Op Fl a Ar argv0
+.Op Fl c
.Op Ar command Op Ar arg ...
.Xc
The command is executed without forking, replacing the shell process.
+This is currently absolute, i.e.\&
+.Ic exec
+never returns, even if the
+.Ar command
+is not found.
+The
+.Fl a
+option permits setting a different
+.Li argv[0]
+value, and
+.Fl c
+clears the environment before executing the child process, except for the
+.Ev _
+variable and direct assignments.
.Pp
If no command is given except for I/O redirection, the I/O redirection is
permanent and the shell is
Since expressions may need to be quoted,
.No \&(( Ar expr No ))
is syntactic sugar for
-.No let \&" Ns Ar expr Ns \&" .
+.No "{ let '" Ns Ar expr Ns "'; }" .
.Pp
.It Ic let]
Internally used alias for
and
.Ar minor
(minor device number).
-.Pp
-See
-.Xr mknod 8
-for further information.
+This is not normally part of
+.Nm mksh ;
+however, distributors may have added this as builtin as a speed hack.
.Pp
.It Xo
.Ic print
-.Oo Fl nprsu Ns Oo Ar n Oc \*(Ba
+.Oo Fl Anprsu Ns Oo Ar n Oc \*(Ba
.Fl R Op Fl en Oc
.Op Ar argument ...
.Xc
option prints to the co-process (see
.Sx Co-processes
above).
+The
+.Fl A
+option prints the character corresponding to each
+.Ar argument Ns 's value .
.Pp
The
.Fl R
.Xr printf 1 ,
utility, except it uses the same
.Sx Backslash expansion
-and I/O code and does hot handle floating point as the rest of
+and I/O code and does not handle floating point as the rest of
.Nm mksh .
+An external utility is preferred over the builtin.
This is not normally part of
.Nm mksh ;
however, distributors may have added this as builtin as a speed hack.
.Ev REPLY )
as array of characters (wide characters if the
.Ic utf8\-mode
-option is enacted, octets otherwise).
+option is enacted, octets otherwise); the codepoints are
+encoded as decimal numbers by default.
.It Fl d Ar x
Use the first byte of
.Ar x ,
.It Fl N Ar z
Instead of reading till end-of-line, read exactly
.Ar z
-bytes; less if EOF or a timeout occurs.
+bytes.
+If EOF or a timeout occurs, a partial read is returned with exit status 1.
.It Fl n Ar z
Instead of reading till end-of-line, read up to
.Ar z
Interrupt reading after
.Ar n
seconds (specified as positive decimal value with an optional fractional part).
+The exit status of
+.Nm read
+is 1 if the timeout occurred, but partial reads may still be returned.
.It Fl r
Normally, the ASCII backslash character escapes the special
meaning of the following character and is stripped from the input;
You might want to use
.Ic while IFS= read \-r foo; do ...; done
for pristine I/O.
-Similarily, when using the
+Similarly, when using the
.Fl a
option, use of the
.Fl r
option might be prudent; the same applies for:
.Bd -literal -offset indent
-find . \-type f \-print0 \*(Ba \e
- while IFS= read \-d \*(aq\*(aq \-r filename; do
+find . \-type f \-print0 \*(Ba& \e
+ while IFS= read \-d \*(aq\*(aq \-pr filename; do
print \-r \-\- "found \*(Lt${filename#./}\*(Gt"
done
.Ed
.Ic realpath
returns 0 if the pathname either exists or can be created immediately,
i.e. all but the last component exist and are directories.
+For calls from the shell, if any options are given, an external
+.Xr realpath 1
+utility is preferred over the builtin.
.Pp
.It Xo
.Ic rename
to
.Ar to .
Both must be complete pathnames and on the same device.
-This builtin is intended for emergency situations where
-.Pa /bin/mv
-becomes unusable, and directly calls
+An external utility is preferred over this builtin,
+which is intended for emergency situations
+.Pq where Pa /bin/mv No becomes unusable
+and directly calls
.Xr rename 2 .
.Pp
.It Ic return Op Ar status
Returns from a function or
-.Ic .\&
+.Ic \&.
script, with exit status
.Ar status .
If no
.Ar status
is given, the exit status of the last executed command is used.
If used outside of a function or
-.Ic .\&
+.Ic \&.
script, it has the same effect as
.Ic exit .
Note that
treats both profile and
.Ev ENV
files as
-.Ic .\&
+.Ic \&.
scripts, while the original Korn shell only treats profiles as
-.Ic .\&
+.Ic \&.
scripts.
.Pp
.It Xo
.Nm ksh93
is:
.Ic foo=(a b c); foo+=(d e)
-.Pp
-Another
-.At
-.Nm ksh93
-and
-.Tn GNU
-.Nm bash
-extension allows specifying the indices used for
-.Ar arg ...
-.Pq from the above example, Ic a b c
-like this:
-.Ic set \-A foo \-\- [0]=a [1]=b [2]=c
-or
-.Ic foo=([0]=a [1]=b [2]=c)
-which can also be written
-.Ic foo=([0]=a b c)
-because indices are incremented automatically.
.It Fl a \*(Ba Fl o Ic allexport
All new parameters are created with the export attribute.
.It Fl b \*(Ba Fl o Ic notify
.Ic until ,
.Ic while ,
or
-.Ic !\&
+.Ic \&!
statements.
For
.Ic &&
case-insensitively; for direct builtin calls depending on the
aforementioned environment variables; or for stdin or scripts,
if the input begins with a UTF-8 Byte Order Mark.
+.Pp
+In near future, locale tracking will be implemented, which means that
+.Ic set Fl +U
+is changed whenever one of the
+.Tn POSIX
+locale-related environment variables changes.
.It Fl u \*(Ba Fl o Ic nounset
Referencing of an unset parameter, other than
.Dq $@
Make the exit status of a pipeline (before logically complementing) the
rightmost non-zero errorlevel, or zero if all commands exited with zero.
.It Fl o Ic posix
-Enable a somewhat more
-.Px
-ish mode.
+Behave closer to the standards
+(see
+.Sx POSIX mode
+for details).
+Automatically enabled if the basename of the shell invocation begins with
+.Dq sh
+and this autodetection feature is compiled in
+.Pq not in MirBSD .
As a side effect, setting this flag turns off
.Ic braceexpand
mode, which can be turned back on manually, and
.Ic sh
-mode.
+mode (unless both are enabled at the same time).
.It Fl o Ic sh
Enable
.Pa /bin/sh
.Pq kludge
-mode.
+mode (see
+.Sx SH mode ) .
Automatically enabled if the basename of the shell invocation begins with
.Dq sh
and this autodetection feature is compiled in
.Ic braceexpand
mode, which can be turned back on manually, and
.Ic posix
-mode.
+mode (unless both are enabled at the same time).
.It Fl o Ic vi
Enable
.Xr vi 1 Ns -like
with no option name will list all the options and whether each is on or off;
.Ic set +o
will print the long names of all options that are currently on.
+In a future version,
+.Ic set +o
+will behave
+.Tn POSIX
+compliant and print commands to restore the current options instead.
.Pp
Remaining arguments, if any, are positional parameters and are assigned, in
order, to the positional parameters (i.e. $1, $2, etc.).
Like
.Ic \&. Po Do dot Dc Pc ,
except that the current working directory is appended to the
-.Ev PATH
-in GNU
+search path (GNU
.Nm bash
-and
-.Nm mksh .
-In
-.Nm ksh93
-and
-.Nm mksh ,
-this is implemented as a shell alias instead of a builtin.
+extension).
.Pp
.It Ic suspend
Stops the shell as if it had received the suspend character from
0m0.00s 0m0.00s
.Ed
.Pp
+.It Ic trap Ar n Op Ar signal ...
+If the first operand is a decimal unsigned integer, this resets all
+specified signals to the default action, i.e. is the same as calling
+.Ic trap
+with a minus sign
+.Pq Sq \-
+as
+.Ar handler ,
+followed by the arguments
+.Pq Ar n Op Ar signal ... ,
+all of which are treated as signals.
+.Pp
.It Ic trap Op Ar handler signal ...
-Sets a trap handler that is to be executed when any of the specified signals are
-received.
+Sets a trap handler that is to be executed when any of the specified
+.Ar signal Ns s
+are received.
.Ar handler
-is either a
-.Dv NULL
-string, indicating the signals are to be ignored, a minus sign
+is either an empty string, indicating the signals are to be ignored,
+a minus sign
.Pq Sq \- ,
-indicating that the default action is to be taken for the signals (see
-.Xr signal 3 ) ,
-or a string containing shell commands to be evaluated and executed at the first
-opportunity (i.e. when the current command completes, or before printing the
-next
+indicating that the default action is to be taken for the signals
+.Pq see Xr signal 3 ,
+or a string containing shell commands to be executed at the first opportunity
+(i.e. when the current command completes, or before printing the next
.Ev PS1
prompt) after receipt of one of the signals.
.Ar signal
-is the name of a signal (e.g.\&
-.Dv PIPE
-or
-.Dv ALRM )
+is the name of a signal
+.Pq e.g.\& Dv PIPE or Dv ALRM
or the number of the signal (see the
-.Ic kill \-l
+.Ic kill Fl l
command above).
.Pp
There are two special signals:
.Dv EXIT
-(also known as 0) which is executed when the shell is about to exit, and
+.Pq also known as 0 ,
+which is executed when the shell is about to exit, and
.Dv ERR ,
-which is executed after an error occurs (an error is something that would cause
-the shell to exit if the
-.Fl e
+which is executed after an error occurs; an error is something
+that would cause the shell to exit if the
+.Ic set Fl e
or
-.Ic errexit
-option were set \*(en see the
-.Ic set
-command above).
+.Ic set Fl o Ic errexit
+option were set.
.Dv EXIT
handlers are executed in the environment of the last executed command.
-Note
-that for non-interactive shells, the trap handler cannot be changed for signals
-that were ignored when the shell started.
.Pp
-With no arguments,
-.Ic trap
-lists, as a series of
+Note that, for non-interactive shells, the trap handler cannot be changed
+for signals that were ignored when the shell started.
+.Pp
+With no arguments, the current state of the traps that have been set since
+the shell started is shown as a series of
.Ic trap
-commands, the current state of the traps that have been set since the shell
-started.
+commands.
Note that the output of
.Ic trap
cannot be usefully piped to another process (an artifact of the fact that
.Ic wait
is that of the last specified job; if the last job is killed by a signal, the
exit status is 128 + the number of the signal (see
-.Ic kill \-l Ar exit-status
+.Ic kill Fl l Ar exit-status
above); if the last specified job can't be found (because it never existed, or
had already finished), the exit status of
.Ic wait
.Op Fl pv
.Op Ar name ...
.Xc
-For each
-.Ar name ,
-the type of command is listed (reserved word, built-in, alias,
-function, tracked alias, or executable).
-If the
-.Fl p
-option is used, a path search is performed even if
-.Ar name
-is a reserved word, alias, etc.
Without the
.Fl v
-option,
-.Ic whence
-is similar to
-.Ic command Fl v
-except that
-.Ic whence
-will find reserved words and won't print aliases as alias commands.
+option, it is the same as
+.Ic command Fl v ,
+except aliases are not printed as alias command.
With the
.Fl v
-option,
-.Ic whence
-is the same as
+option, it is exactly the same as
.Ic command Fl V .
-Note that for
-.Ic whence ,
-the
+In either case, the
.Fl p
-option does not affect the search path used, as it does for
-.Ic command .
-If the type of one or more of the names could not be determined, the exit
-status is non-zero.
+option differs: the search path is not affected in
+.Ic whence ,
+but the search is restricted to the path.
.El
.Ss Job control
Job control refers to the shell's ability to monitor and control jobs which
.Ic jobs
commands.
If job control is fully enabled (using
-.Ic set \-m
+.Ic set Fl m
or
-.Ic set \-o monitor ) ,
+.Ic set Fl o Ic monitor ) ,
as it is for interactive shells, the processes of a job are placed in their
own process group.
Foreground jobs can be stopped by typing the suspend
.Dv SIGTSTP ) .
.It Ar signal-description Op Dq core dumped
The job was killed by a signal (e.g. memory fault, hangup); use
-.Ic kill \-l
+.Ic kill Fl l
for a list of signal descriptions.
The
.Dq core dumped
is immediately made to exit the shell, the running jobs are sent a
.Dv SIGHUP
signal and the shell exits.
+.Ss POSIX mode
+Entering
+.Ic set Fl o Ic posix
+mode will cause
+.Nm
+to behave even more
+.Tn POSIX
+compliant in places where the defaults or opinions differ.
+Note that
+.Nm mksh
+will still operate with unsigned 32-bit arithmetics; use
+.Nm lksh
+if arithmetics on the host
+.Vt long
+data type, complete with ISO C Undefined Behaviour, are required;
+refer to the
+.Xr lksh 1
+manual page for details.
+Most other historic,
+.At
+.Nm ksh Ns -compatible ,
+or opinionated differences can be disabled by using this mode; these are:
+.Bl -bullet
+.It
+The GNU
+.Nm bash
+I/O redirection
+.Ic &\*(Gt Ns Ar file
+is no longer supported.
+.It
+File descriptors created by I/O redirections are inherited by
+child processes.
+.It
+Numbers with a leading digit zero are interpreted as octal.
+.It
+The
+.Nm echo
+builtin does not interpret backslashes and only supports the exact option
+.Dq Fl n .
+.It
+\&... (list is incomplete and may change for R54)
+.El
+.Ss SH mode
+Compatibility mode; intended for use with legacy scripts that
+cannot easily be fixed; the changes are as follows:
+.Bl -bullet
+.It
+The GNU
+.Nm bash
+I/O redirection
+.Ic &\*(Gt Ns Ar file
+is no longer supported.
+.It
+File descriptors created by I/O redirections are inherited by
+child processes.
+.It
+The
+.Nm echo
+builtin does not interpret backslashes and only supports the exact option
+.Dq Fl n .
+.It
+The substitution operations
+.Sm off
+.Xo
+.Pf ${ Ar x
+.Pf # Ar pat No } ,
+.Sm on
+.Xc
+.Sm off
+.Xo
+.Pf ${ Ar x
+.Pf ## Ar pat No } ,
+.Sm on
+.Xc
+.Sm off
+.Xo
+.Pf ${ Ar x
+.Pf % Ar pat No } ,
+.Sm on
+.Xc
+and
+.Sm off
+.Xo
+.Pf ${ Ar x
+.Pf %% Ar pat No }
+.Sm on
+.Xc
+wrongly do not require a parenthesis to be escaped and do not parse extglobs.
+.It
+\&... (list is incomplete and may change for R54)
+.El
.Ss Interactive input line editing
The shell supports three modes of reading command lines from a
.Xr tty 4
command.
Furthermore, many editing commands are useful only on terminals with
a visible cursor.
-The default bindings were chosen to resemble corresponding
-Emacs key bindings.
The user's
.Xr tty 4
characters (e.g.\&
.Dv ERASE )
are bound to
-reasonable substitutes and override the default bindings.
+reasonable substitutes and override the default bindings;
+their customary values are shown in parentheses below.
+The default bindings were chosen to resemble corresponding
+Emacs key bindings:
.Bl -tag -width Ds
-.It abort: \*(haC, \*(haG
+.It Xo abort:
+.No INTR Pq \*(haC ,
+.No \*(haG
+.Xc
Abort the current command, empty the line buffer and
set the exit state to interrupted.
.It auto\-insert: Op Ar n
Most ordinary characters are bound to this.
.It Xo backward\-char:
.Op Ar n
-.No \*(haB , \*(haXD , ANSI-CurLeft
+.No \*(haB , \*(haXD , ANSI-CurLeft , PC-CurLeft
.Xc
Moves the cursor backward
.Ar n
characters.
.It beginning\-of\-history: \*(ha[\*(Lt
Moves to the beginning of the history.
-.It beginning\-of\-line: \*(haA, ANSI-Home
+.It beginning\-of\-line: \*(haA, ANSI-Home, PC-Home
Moves the cursor to the beginning of the edited input line.
.It Xo capitalise\-word:
.Op Ar n
Note that \*(haI is usually generated by the TAB (tabulator) key.
.It Xo delete\-char\-backward:
.Op Ar n
-.No ERASE , \*(ha? , \*(haH
+.No ERASE Pq \*(haH ,
+.No \*(ha? , \*(haH
.Xc
Deletes
.Ar n
characters before the cursor.
.It Xo delete\-char\-forward:
.Op Ar n
-.No ANSI-Del
+.No ANSI-Del , PC-Del
.Xc
Deletes
.Ar n
characters after the cursor.
.It Xo delete\-word\-backward:
.Op Ar n
-.No WERASE , \*(ha[\*(ha? , \*(ha[\*(haH , \*(ha[h
+.No Pfx1+ERASE Pq \*(ha[\*(haH ,
+.No WERASE Pq \*(haW ,
+.No \*(ha[\*(ha? , \*(ha[\*(haH , \*(ha[h
.Xc
Deletes
.Ar n
words.
.It Xo down\-history:
.Op Ar n
-.No \*(haN , \*(haXB , ANSI-CurDown
+.No \*(haN , \*(haXB , ANSI-CurDown , PC-CurDown
.Xc
Scrolls the history buffer forward
.Ar n
.Ic fc \-e ${VISUAL:\-${EDITOR:\-vi}} Ar n .
.It end\-of\-history: \*(ha[\*(Gt
Moves to the end of the history.
-.It end\-of\-line: \*(haE, ANSI-End
+.It end\-of\-line: \*(haE, ANSI-End, PC-End
Moves the cursor to the end of the input line.
.It eot: \*(ha_
Acts as an end-of-file; this is useful because edit-mode input disables
-normal terminal input canonicalization.
+normal terminal input canonicalisation.
.It Xo eot\-or\-delete:
.Op Ar n
-.No \*(haD
+.No EOF Pq \*(haD
.Xc
-Acts as
-.Ic eot
-if alone on a line; otherwise acts as
+If alone on a line, same as
+.Ic eot ,
+otherwise,
.Ic delete\-char\-forward .
.It error: (not bound)
Error (ring the bell).
+.It evaluate\-region: \*(ha[\*(haE
+Evaluates the text between the mark and the cursor position
+.Pq the entire line if no mark is set
+as function substitution (if it cannot be parsed, the editing state is
+unchanged and the bell is rung to signal an error); $? is updated accordingly.
.It exchange\-point\-and\-mark: \*(haX\*(haX
Places the cursor where the mark is and sets the mark to where the cursor was.
.It expand\-file: \*(ha[*
If no files match the pattern, the bell is rung.
.It Xo forward\-char:
.Op Ar n
-.No \*(haF , \*(haXC , ANSI-CurRight
+.No \*(haF , \*(haXC , ANSI-CurRight , PC-CurRight
.Xc
Moves the cursor forward
.Ar n
.Xc
Goes to history number
.Ar n .
-.It kill\-line: KILL
+.It Xo kill\-line:
+.No KILL Pq \*(haU
+.Xc
Deletes the entire input line.
+If Ctrl-U should only delete the line up to the cursor, use:
+.Pp
+.D1 $ bind \-m \*(haU='\*(ha[0\*(haK'
.It kill\-region: \*(haW
Deletes the input between the cursor and the mark.
.It Xo kill\-to\-eol:
.Ic search\-history
or
.Ic search\-history\-up .
-.It no\-op: QUIT
+.It Xo no\-op:
+.No QUIT Pq \*(ha\e
+.Xc
This does nothing.
.It prefix\-1: \*(ha[
Introduces a 2-character command sequence.
.It prefix\-2: \*(haX , \*(ha[[ , \*(ha[O
-Introduces a 2-character command sequence.
+Introduces a multi-character command sequence.
.It Xo prev\-hist\-word:
.Op Ar n
.No \*(ha[. , \*(ha[_
pattern.
The history buffer retains only a finite number of lines; the oldest
are discarded as necessary.
-.It search\-history\-up: ANSI-PgUp
+.It search\-history\-up: ANSI-PgUp, PC-PgUp
Search backwards through the history buffer for commands whose beginning match
the portion of the input line before the cursor.
When used on an empty line, this has the same effect as
.Ic up\-history .
-.It search\-history\-down: ANSI-PgDn
+.It search\-history\-down: ANSI-PgDn, PC-PgDn
Search forwards through the history buffer for commands whose beginning match
the portion of the input line before the cursor.
When used on an empty line, this has the same effect as
character to the right.
.It Xo up\-history:
.Op Ar n
-.No \*(haP , \*(haXA , ANSI-CurUp
+.No \*(haP , \*(haXA , ANSI-CurUp , PC-CurUp
.Xc
Scrolls the history buffer backward
.Ar n
.Ic yank ,
replaces the inserted text string with the next previously killed text string.
.El
+.Pp
+The tab completion escapes characters the same way as the following code:
+.Bd -literal
+print \-nr \-\- "${x@/[\e"\-\e$\e&\-*:\-?[\e\e\e\`{\-\e}${IFS\-$\*(aq \et\en\*(aq}]/\e\e$KSH_MATCH}"
+.Ed
.Ss Vi editing mode
.Em Note:
The vi command-line editing mode is orphaned, yet still functional.
Optional file name and command completion (see
.Ic \*(haF
above), enabled with
-.Ic set \-o vi\-tabcomplete .
+.Ic set Fl o Ic vi\-tabcomplete .
.El
.Pp
In command mode, each character is interpreted as a command.
is only recognised if the
.Ic vi\-esccomplete
option is set (see
-.Ic set \-o ) .
+.Ic set Fl o ) .
If
.Ar n
is specified, the
.Ar n Ns th
occurrence of the last search string;
the direction of the search is the opposite of the last search.
-.It Ar ANSI-CurUp
+.It Ar ANSI-CurUp , PC-PgUp
Take the characters from the beginning of the line to the current
cursor position as search string and do a backwards history search
for lines beginning with this string; keep the cursor position.
Undo the last edit command.
.It U
Undo all changes that have been made to the current line.
+.It PC Home, End, Del, and cursor keys
+They move as expected, both in insert and command mode.
.It Ar intr No and Ar quit
The interrupt and quit terminal characters cause the current line to be
deleted and a new prompt to be printed.
.Xr cat 1 ,
.Xr ed 1 ,
.Xr getopt 1 ,
+.Xr lksh 1 ,
.Xr sed 1 ,
.Xr sh 1 ,
.Xr stty 1 ,
.Xr utf\-8 7 ,
.Xr mknod 8
.Pp
-.Pa http://docsrv.sco.com:507/en/man/html.C/sh.C.html
-.Pp
.Pa https://www.mirbsd.org/ksh\-chan.htm
.Rs
.%A Morris Bolsky
.An -nosplit
.Nm "The MirBSD Korn Shell"
is developed by
-.An Thorsten Glaser Aq tg@mirbsd.org
-and currently maintained as part of The MirOS Project.
+.An mirabilos Aq Mt m@mirbsd.org
+as part of The MirOS Project.
This shell is based on the public domain 7th edition Bourne shell clone by
.An Charles Forsyth ,
who kindly agreed to, in countries where the Public Domain status of the work
was created by
.An Eric Gisin ,
and it was subsequently maintained by
-.An John R. MacMillan Aq Mt change!john@sq.sq.com ,
-.An Simon J. Gerraty Aq Mt sjg@zen.void.oz.au ,
+.An John R. MacMillan ,
+.An Simon J. Gerraty ,
and
-.An Michael Rendell Aq Mt michael@cs.mun.ca .
+.An Michael Rendell .
The effort of several projects, such as Debian and OpenBSD, and other
contributors including our users, to improve the shell is appreciated.
See the documentation, CVS, and web site for details.
.Pa https://www.mirbsd.org/TaC\-mksh.txt
.\"
.\" This boils down to: feel free to use mksh.ico as application icon
-.\" or shortcut for mksh or mksh/Win32; distro patches are ok (but we
-.\" request they amend $KSH_VERSION when modifying mksh). Authors are
-.\" Marshall Kirk McKusick (UCB), Rick Collette (ekkoBSD), Thorsten
-.\" Glaser, Benny Siegert (MirBSD), Michael Langguth (mksh/Win32).
+.\" or shortcut for mksh or mksh/Win32 or OS/2; distro patches are ok
+.\" (but we request they amend $KSH_VERSION when modifying mksh).
+.\" Authors are Marshall Kirk McKusick (UCB), Rick Collette (ekkoBSD),
+.\" mirabilos, Benny Siegert (MirBSD), Michael Langguth (mksh/Win32),
+.\" KO Myung-Hun (mksh for OS/2).
.\"
.\" As far as MirBSD is concerned, the files themselves are free
.\" to modification and distribution under BSD/MirOS Licence, the
.\"
.Sh CAVEATS
.Nm
-only supports the Unicode BMP (Basic Multilingual Plane).
-.Pp
-.Nm
has a different scope model from
.At
.Nm ksh ,
.Pp
.Nm mksh
provides a consistent set of 32-bit integer arithmetics, both signed
-and unsigned, with defined wraparound and sign of the result of a modulo
-operation, even (defying POSIX) on 64-bit systems.
-If you require 64-bit integer arithmetics, use
-.Nm lksh Pq legacy mksh
-instead, but be aware that, in POSIX, it's legal for the OS to make
-.Li print $((2147483647 + 1))
-delete all files on your system, as it's Undefined Behaviour.
+and unsigned, with defined wraparound and sign of the result of a
+remainder operation, even (defying POSIX) on 36-bit and 64-bit systems.
+.Pp
+.Nm mksh
+provides a consistent, clear interface normally.
+This may deviate from POSIX in historic or opinionated places.
+.Ic set Fl o Ic posix
+(see
+.Sx POSIX mode
+for details)
+will cause the shell to behave more conformant.
+.Pp
+For the purpose of
+.Tn POSIX ,
+.Nm mksh
+supports only the
+.Dq C
+locale.
+.Nm mksh Ns 's
+.Ic utf8\-mode
+only supports the Unicode BMP (Basic Multilingual Plane) and maps
+raw octets into the U+EF80..U+EFFF wide character range; compare
+.Sx Arithmetic expressions .
+The following
+.Tn POSIX
+.Nm sh
+code toggles the
+.Ic utf8\-mode
+option dependent on the current
+.Tn POSIX
+locale for mksh to allow using the UTF-8 mode, within the constraints
+outlined above, in code portable across various shell implementations:
+.Bd -literal -offset indent
+case ${KSH_VERSION:\-} in
+*MIRBSD\ KSH*\*(Ba*LEGACY\ KSH*)
+ case ${LC_ALL:\-${LC_CTYPE:\-${LANG:\-}}} in
+ *[Uu][Tt][Ff]8*\*(Ba*[Uu][Tt][Ff]\-8*) set \-U ;;
+ *) set +U ;;
+ esac ;;
+esac
+.Ed
+In near future, (Unicode) locale tracking will be implemented though.
.Sh BUGS
Suspending (using \*(haZ) pipelines like the one below will only suspend
the currently running part of the pipeline; in this example,
$ /bin/sleep 666 && echo fubar
.Ed
.Pp
+The truncation process involved when changing
+.Ev HISTFILE
+does not free old history entries (leaks memory) and leaks
+old entries into the new history if their line numbers are
+not overwritten by same-numer entries from the persistent
+history file; truncating the on-disc file to
+.Ev HISTSIZE
+lines has always been broken and prone to history file corruption
+when multiple shells are accessing the file; the rollover process
+for the in-memory portion of the history is slow, should use
+.Xr memmove 3 .
+.Pp
This document attempts to describe
-.Nm mksh\ R50
+.Nm mksh\ R53
and up,
+.\" with vendor patches from insert-your-name-here,
compiled without any options impacting functionality, such as
.Dv MKSH_SMALL ,
when not called as
.Pa /bin/sh
which, on some systems only, enables
-.Ic set \-o sh
+.Ic set Fl o Ic posix
+or
+.Ic set Fl o Ic sh
automatically (whose behaviour differs across targets),
for an operating environment supporting all of its advanced needs.
+.Pp
Please report bugs in
.Nm
to the
.Mx
mailing list at
-.Aq miros\-mksh@mirbsd.org
+.Aq Mt miros\-mksh@mirbsd.org
or in the
.Li \&#\&!/bin/mksh
.Pq or Li \&#ksh