.nr OJ 1 \" Job Control .nr OE 1 \" Command Editing .nr OB 1 \" BSD enhanced ulimit options
Features of the Korn shell are described in more detail. Only a subset of the Korn shell features are currently implemented.
In the following syntax, { ... }? indicates an optional thing, { ... }* indicates zero or more repetitions, { ... | ... } indicates alternatives.
\\$1
..
Expression may contain alpha-numeric variable identifiers and integer constants and may be combined with the following operators:
Any keyword assignments are then performed according to the type of command. In function calls assignments are local to the function. Assignments in built-in commands marked with a \(dg persist, otherwise they are temporary. Assignments in executable commands are exported to the sub-process executing the command.
Even on systems where the exec() family does not support #! notation for scripts, ksh can be configured to fake it.
There are several built-in commands.
alias -d fac=/usr/local/usr/facilities
\t\\$1\t\\$2\t\\$3 ..
If options but no names are given, lists variables with specified attributes, and their values if unless ``+'' is used.
If names are given, set the attributes of the named variables. Variables may also be assigned a value. If used inside a function, the created variable are local to the function.
The attributes are as follows. \t-i\tThe variable's value is stored as an integer.
\t-x\tThe variable is exported to the enviroment.
\t-r\tThe variable is read-only cannot be reassigned a value.
\t-t\tTrace (not implemented).
\t-f\tList functions instead of variable.
.IP "ulimit [-f] [value]"
"\w'-- 'u" Impose a size limit of n\^ blocks on the size of core dumps.
-d Impose a size limit of n\^ blocks on the size of the data area.\}
-f Impose a size limit of n blocks on files written by the shell and its child processes (files of any size may be read). -m Impose a soft limit of n\^ blocks on the size of physical memory.
-t Impose a time limit of n\^ seconds to be used by each process.\}
If no option is given, -f is assumed. If n is omitted, the current limit is printed. As far as ulimit is concerned, a ``block'' is 512 bytes.
You may lower your own resource limit, but only a super-user (see su (1M)) can raise a limit.
0
"\w'kill \*(OK job \*(CK 'u" jobs Display information about the controlled jobs. The job number is given preceeded by a percent sign, followed by a plus sign if it is the ``current job'', or by a minus sign if it is the ``previous job'', then the process group number for the job, then the command.
kill [-signal] job ... Send a signal (TERM by default) to the named job process group.
fg \*(OK job \*(CK Resume the stopped foreground job in the foreground. If the process group n is not specified then the ``current job'' is resumed.
bg \*(OK job \*(CK Resume the stopped foreground job in the background. If the process group n is not specified then the ``current job'' is resumed.
The fg, bg, kill, and wait commands may refer to jobs with the following ``percent'' sequences. The percent sign is optional with the fg and bg commands.
0
"\w'bg \*(OK n \*(CK 'u" %+ ( %- ) If there is a ``current job'' (``previous job''), then that job is selected.
% n If the specified job number is one of the known jobs, then that job is selected.
% string If the string matches the initial part of a job's command, then that job is selected.
%? string As above, but the string may match any portion of the command.
If the system does not support job control, monitor mode enables job reporting. The jobs and kill commands functions as above, and you will be informed when background jobs complete. Fg and bg are not availiable.
0
2i bind The current bindings are listed.
bind \*(OK string \*(CK = \*(OK editing-command \*(CK The specified "editing command\^" is bound to the given string , which should consist of a control character (which may be written using ``caret notation'' ^x\|), optionally preceded by one of the two prefix characters. Future input of the string will cause the "editing command\^" to be immediately invoked.
Note that although only two prefix characters (normal ESC and ^X) are supported, some multi-character sequences can be supported:
bind '^[['=prefix-2
bind '^XA'=up-history
bind '^XB'=down-history
bind '^XC'=forward-char
bind '^XC'=backward-char
will bind the arrow keys on an ANSI terminal. Of course some escape sequences won't work out quite that nicely.
bind -m \*(OK string \*(CK = \*(OK substitute \*(CK The specified input string will afterwards be immediately replaced by the given substitute string, which may contain "editing commands" .
The following "editing commands" are available; first the command name is given followed by its default binding (if any) using caret notation (note that the ASCII ESC character is written as \s-1^[\s0\|), then the editing function performed is decribed. Note that "editing command" names are used only with the bind 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 users tty characters (eg. erase) are bound to reasonable substitutes.
0
"\w'delete-word-backward ^[\|ERASE 'u" abort ^G Useful as a response to a request for a search-history pattern in order to abort the search.
auto-insert Simply causes the character to appear as literal input. (Most ordinary characters are bound to this.)
backward-char ^B Moves the cursor backward one character.
backward-word ^[\|b Moves the cursor backward to the beginning of a word.
beginning-of-line ^A Moves the cursor to the beginning of the input line (after the prompt string).
complete ^[\|^[ Automatically completes as much as is unique of the hashed command name or the file name containing the cursor. If the entire remaining command or file name is unique a space is printed after its completion, unless it is a directory name in which case / is postpended. If there is no hashed command or file name with the current partial word as its prefix, a bell character is output (usually causing a ``beep'').
complete-command ^X^[ Automatically completes as much as is unique of the hashed command name having the partial word up to the cursor as its prefix, as in the complete command described above. Only command and function names seen since the last "hash -r" command are available for completion; the "hash" command may be used to register additional names.
complete-file ^[\|^X Automatically completes as much as is unique of the file name having the partial word up to the cursor as its prefix, as in the complete command described above.
copy-last-arg ^[\|_ The last word of the previous command is inserted at the cursor. Note I/O redirections do not count as words of the command.
delete-char-backward ERASE Deletes the character before the cursor.
delete-char-forward Deletes the character after the cursor.
delete-word-backward ^[\|ERASE Deletes characters before the cursor back to the beginning of a word.
delete-word-forward ^[\|d Deletes characters after the cursor up to the end of a word.
down-history ^N Scrolls the history buffer forward one line (later). Each input line originally starts just after the last entry in the history buffer, so down-history is not useful until either search-history or up-history has been performed.
end-of-line ^E Moves the cursor to the end of the input line.
eot ^_ Acts as an end-of-file; this is useful because edit-mode input disables normal terminal input canonicalization.
eot-or-delete ^D Acts as eot if alone on a line; otherwise acts as delete-char-forward.
exchange-point-and-mark ^X\|^X Places the cursor where the mark is, and sets the mark to where the cursor was.
forward-char ^F Moves the cursor forward one position.
forward-word ^[\|f Moves the cursor forward to the end of a word.
kill-line KILL Deletes the entire input line.
kill-to-eol ^K Deletes the input from the cursor to the end of the line.
kill-region ^W Deletes the input between the cursor and the mark.
list ^[\|? Prints a sorted, columnated list of hashed command names or file names (if any) that can complete the partial word containing the cursor. Directory names have / postpended to them, and executable file names are followed by \(** .
list-command ^X\|? Prints a sorted, columnated list of hashed command names (if any) that can complete the partial word containing the cursor.
list-file Prints a sorted, columnated list of file names (if any) that can complete the partial word containing the cursor. File type indicators are postpended as described under list above.
newline ^J and\^ ^M Causes the current input line to be processed by the shell. (The current cursor position may be anywhere on the line.)
newline-and-next ^O Causes the current input line to be processed by the shell, and the next line from history becomes the current line. This is only useful after an up-history or search-history.
no-op QUIT Does nothing.
prefix-1 ^[ Introduces a 2-character command sequence.
prefix-2 ^X Introduces a 2-character command sequence.
quote ^^ The following character is taken literally rather than as an "editing command" .
redraw ^L Reprints the prompt string and the current input line.
search-character ^] Search forward in the current line for the next keyboard character.
search-history ^R Enter incremental search mode. The internal history list is searched backwards for commands matching the input. An initial ``^'' in the search string anchors the search. The escape key will leave search mode. Other commands will be executed after leaving search mode (unless of course they are prefixed by escape, in which case they will almost certainly do the wrong thing). Successive search-history commands continue searching backward to the next previous occurrence of the pattern. The history buffer retains only a finite number of lines; the oldest are discarded as necessary.
set-mark-command ^]\|<space> Search forward in the current line for the next keyboard character.
stuff ^T\} stuff\} On systems supporting it, pushes the bound character back onto the terminal input where it may receive special processing by the terminal handler. ^T ``mini-systat'' feature, for example.\}
stuff-reset Acts like stuff\^ , then aborts input the same as an interrupt.
transpose-chars\} transpose-chars ^T\} Exchanges the two characters on either side of the cursor, or the two previous characters if the cursor is at end of line.
up-history ^P Scrolls the history buffer backward one line (earlier).
yank ^Y Inserts the most recently killed text string at the current cursor position.
yank-pop ^[\|y Immediately after a yank , replaces the inserted text string with the next previous killed text string.
"UNIX Shell Programming," Stephan G. Kochan, Patrick H. Wood, Hayden.
"KornShell: Command and Programming Language (not yet published)," Morris Bolsky and David Korn.
System V and Korn modifications by Eric Gisin, with contributions by Ron Natalie, Arnold Robbins, Doug Gwyn, Erik Baalbergen, AT&T (getopt(3)), John McMillan and Simon Gerraty.
The 8th bit is stripped in emacs mode.
Quoting double-quote (") characters inside back-quote (`) inside double-quotes does not behave properly. Why are you doing this?
The emacs mode can ``lose'' stty command done by the user.
Unsetting special variables may cause unexpected results.
Functions declared as having local scope really have global scope.
Here documents inside functions do not work correctly.
Exit on error (set -e or set -o errexit) does not work correctly.
\\$1\t\\$2 ..
[ expression ]
The following basic expressions are available.
.X "-r file" "file exists and is readable" .X "-w file" "file exists and is writable" .X "-x file" "file exists and is executable" .X "-f file" "file is a regular file" .X "-d file" "file is a directory" .X "-c file" "file is a character special device" .X "-b file" "file is a block special device" .X "-p file" "file is a named pipe" .X "-u file" "file mode has setuid bit" .X "-g file" "file mode has setgid bit" .X "-k file" "file mode has sticky bit" .X "-s file" "file is not empty" .X "-L file" "file is a symbolic link" .X "-S file" "file is a socket" .X "file -nt file" "first file is newer than second file" .X "file -ot file" "first file is older than second file" .X "file -ef file" "first file is the same file as second file" .X "-t filedes" "file descriptor is a tty device" .X "string" "string is not null" .X "-z string" "string is null" .X "-n string" "string is not null" .X "string = string" "strings are equal" .X "string != string" "strings are not equal" .X "number -eq number" "numbers compare equal" .X "number -ne number" "numbers compare not equal" .X "number -ge number" "numbers compare greater than or equal" .X "number -gt number" "numbers compare greater than" .X "number -le number" "numbers compare less than or equal" .X "number -lt number" "numbers compare less than"The above basic expressions may be combined with the following operators.
.X "expr -o expr" "logical or" .X "expr -a expr" "logical and" .X "! expr" "logical not" .X "( expr )" "grouping"optstring must contain the option letters the command using getopts will recognize; if a letter is followed by a colon, the option is expected to have an argument which should be separated from it by white space.
Each time it is invoked, getopts will place the next option in the shell variable name and the index of the next argument to be processed in the shell variable \s-1OPTIND\s0 . Whenever the shell or a shell procedure is invoked, \s-1OPTIND\s0 is initialized to 1 .
When an option requires an option-argument, getopts places it in the shell variable \s-1OPTARG\s0 .
If an illegal option is encountered, ?\& will be placed in name .
When the end of the options is encountered, getopts exits with a non-zero exit status. The special option `` -- '' may be used to delimit the end of the options.
By default, getopts parses the positional parameters. If extra arguments ( arg ...) are given on the getopts command line, getopts will parse them instead.
So all new commands will adhere to the command syntax standard described in intro (1), they should use getopts (1) or getopt (3C) to parse positional parameters and check for options that are legal for that command (see \s-1WARNINGS\s0 , below).
.ss 18
while getopts abo: c
do
case $c in
a\(bvb) FLAGS=$FLAGS$c;;
o) OARG=$OPTARG;;
\e?) echo $USAGE 1>&2
exit 2;;
esac
done
shift OPTIND-1
.ss 12
This code will accept any of the following as equivalent:
.ss 18
cmd -a -b -o "xxx z yy" file
cmd -a -b -o "xxx z yy" -- file
cmd -ab -o "xxx z yy" file
cmd -ab -o "xxx z yy" -- file
.ss 12
getopt(3C) in the "Programmer's Reference Manual" .
"UNIX System V Release 3.0 Release Notes" .
cmd -aboxxx file (Rule 5 violation: options with option-arguments must not be grouped with other options) cmd -ab -oxxx file (Rule 6 violation: there must be white space after an option that takes an option-argument)
Changing the value of the shell variable \s-1OPTIND\s0 or parsing different sets of arguments may lead to unexpected results.