Special built-in command descriptions for the Korn shell or POSIX shell

Special commands are built into the Korn shell and POSIX shell and executed in the shell process.

The special built-in commands of the Korn shell are described below:

:               eval             newgrp            shift
.               exec             readonly          times
break           exit             return            trap
continue        export           set               typeset
                                                    unset
                                                

Item Description
: [Argument ...] Expands only arguments. It is used when a command is necessary, as in the then condition of an if command, but nothing is to be done by the command.
. File [Argument ...] Reads the complete specified file and then executes the commands. The commands are executed in the current shell environment. The search path specified by the PATH variable is used to find the directory containing the specified file. If any arguments are specified, they become the positional parameters. Otherwise, the positional parameters are unchanged. The exit status is the exit status of the most recent command executed. See Parameter substitution in the Korn shell or POSIX shell for more information on positional parameters.
Note: The .File [Argument ...] command reads the entire file before any commands are carried out. Therefore, the alias and unalias commands in the file do not apply to any functions defined in the file.
break [n] Exits from the enclosing for, while, until, or select loop, if one exists. If you specify the n parameter, the command breaks the number of levels specified by the n parameter. The value of n is any integer equal to or greater than 1.
continue [n] Resumes the next iteration of the enclosing for, while, until, or select loop. If you specify the n parameter, the command resumes at the nth enclosing loop. The value of n is any integer equal to or greater than 1.
eval [Argument ...] Reads the specified arguments as input to the shell and executes the resulting command or commands.
exec [Argument ...] Executes the command specified by the argument in place of this shell (without creating a new process). Input and output arguments can appear and affect the current process. If you do not specify an argument, the exec command modifies file descriptors as prescribed by the input and output redirection list. In this case, any file descriptor numbers greater than 2 that are opened with this mechanism are closed when invoking another program.
exit [n] Exits the shell with the exit status specified by the n parameter. The n parameter must be an unsigned decimal integer with range 0-255. If you omit the n parameter, the exit status is that of the most recent command executed. An end-of-file character also exits the shell unless the ignoreeof option of the set special command is turned on.
export -p [Name[= Value]] ... Marks the specified names for automatic export to the environment of subsequently executed commands.
-p writes to standard output the names and values of all exported variables, in the following format:
"export %s= %s\n", <name> <value>
newgrp [Group] Equivalent to the exec/usr/bin/newgrp [Group] command.
Note: This command does not return.
readonly -p [Name[= Value]] ... Marks the names specified by the Name parameter as read-only. These names cannot be changed by subsequent assignment.
-p writes to standard output the names and values of all exported variables, in the following format:
"export %s= %s\n", <name> <value>
return [n] Causes a shell function to return to the invoking script. The return status is specified by the n parameter. If you omit the n parameter, the return status is that of the most recent command executed. If you invoke the return command outside of a function or a script, then it is the same as an exit command.
set [+ |-abCefhkmnostuvx ] [+ |-o Option]... [+ |-AName] [Argument ...] If no options or arguments are specified, the set command writes the names and values of all shell variables in the collation sequence of the current locale. When options are specified, they will set or unset attributes of the shell, described as follows:
-A
Array assignment. Unsets the Name parameter and assigns values sequentially from the specified Argument parameter list. If the +A flag is used, the Name parameter is not unset first.
-a
Automatically exports all subsequent parameters that are defined.
-b
Notifies the user asynchronously of background job completions.
-C
Equivalent to set -o noclobber.
-e
Executes the ERR trap, if set, and exits if a command has a nonzero exit status unless the simple command is:
  • + contained in an && or || list
  • + the command immediately following if, while or until
  • + contained in the pipeline following !
This mode is disabled while reading profiles.
-f
Disables file name substitution.
-h
Designates each command as a tracked alias when first encountered.
-k
Places all parameter-assignment arguments in the environment for a command, not only those arguments that precede the command name.
-m
Runs background jobs in a separate process and prints a line upon completion. The exit status of background jobs is reported in a completion message. On systems with job control, this flag is turned on automatically for interactive shells. For more information, see Job control in the Korn shell or POSIX shell.
-n
Reads commands and checks them for syntax errors, but does not execute them. This flag is ignored for interactive shells.
 
-o Option
Prints current option settings and an error message if you do not specify an argument. You can set more than one option on a single ksh command line. If the +o flag is used, the specified option is unset. When arguments are specified, they will cause positional parameters to be set or unset. Arguments, as specified by the Option variable, can be one of the following:
allexport
Same as the -a flag.
bgnice
Runs all background jobs at a lower priority. This is the default mode.
emacs
Enters an emacs-style inline editor for command entry.
errexit
Same as the -e flag.
gmacs
Enters a gmacs-style inline editor for command entry.
ignoreeof
Does not exit the shell when it encounters an end-of-file character. To exit the shell, you must use the exit command or press the Ctrl-D key sequence more than 11 times.
keyword
Same as the -k flag.
Note: This flag is for backward compatibility with the Bourne shell only. Its use is strongly discouraged.
markdirs
Appends a backslash / to all directory names that are a result of file name substitution.
monitor
Same as the -m flag.
noclobber
Prevents redirection from truncating existing files. When you specify this option, a vertical bar must follow the redirection symbol (>|) to truncate a file.
noexec
Same as the -n flag.
noglob
Same as the -f flag.
nolog
Prevents function definitions in .profile and $ENV files from being saved in the history file.
nounset
Same as the -u flag.
privileged
Same as the -p flag.
 
                
trackall
Same as the -h flag.
verbose
Same as the -v flag.
vi
Enters the insert mode of a vi-style inline editor for command entry. Entering escape character 033 puts the editor into the move mode. A return sends the line.
viraw
Processes each character as it is typed in vi mode.
xtrace
Same as the -x flag.
-p
Disables processing of the $HOME/.profile file and uses the /etc/suid_profile file instead of the ENV file. This mode is enabled whenever the effective user ID (UID) or group ID (GID) is not equal to the real UID or GID. Turning off this option sets the effective UID or GID to the real UID and GID.
Note: The system does not support the -p option because the operating system does not support setuid shell scripts.
-s
Sorts the positional parameters lexicographically.
-t
Exits after reading and executing one command.
Note: This flag is for backward compatibility with the Bourne shell only. Its use is strongly discouraged.
-u           
Treats unset parameters as errors when substituting.
-v
Prints shell input lines as they are read.
-x
Prints commands and their arguments as they are executed.
-
Turns off the -x and -v flags and stops examining arguments for flags.
Prevents any flags from being changed. This option is useful in setting the $1 parameter to a value beginning with -. If no arguments follow this flag, the positional parameters are not set.

Preceding any of the set command flags with a + rather than a - turns off the flag. You can use these flags when you invoke the shell. When 'set +o' is invoked without any arguments, it displays the current option settings in a format that is suitable for re-input to the shell as commands that achieve the same option setting. The current set of flags is found in the $- parameter. Unless you specify the -A flag, the remaining arguments are positional parameters and are assigned, in order, to $1, $2, ..., and so on. If no arguments are given, the names and values of all named parameters are printed to standard output.

shift [n] Renames the positional parameters, beginning with $n+1 ... through $1 .... The default value of the n parameter is 1. The n parameter is any arithmetic expression that evaluates to a nonnegative number less than or equal to the $# parameter.
times Prints the accumulated user and system times for the shell and for processes run from the shell.
trap [Command] [Signal] ... Runs the specified command when the shell receives the specified signal or signals. The Command parameter is read once when the trap is set and once when the trap is taken. The Signal parameter can be given as a number or as the name of the signal. Trap commands are executed in order of signal number. Any attempt to set a trap on a signal that was ignored on entry to the current shell is ineffective.
If the command is -, all traps are reset to their original values. If you omit the command and the first signal is a numeric signal number, then the ksh command resets the value of the Signal parameter or parameters to the original values.
Note: If you omit the command and the first signal is a symbolic name, the signal is interpreted as a command.

If the value of the Signal parameter is the ERR signal, the specified command is carried out whenever a command has a nonzero exit status. If the signal is DEBUG, then the specified command is carried out after each command. If the value of the Signal parameter is the 0 or EXIT signal and the trap command is executed inside the body of a function, the specified command is carried out after the function completes. If the Signal parameter is 0 or EXIT for a trap command set outside any function, the specified command is carried out on exit from the shell.

Note: If a script receives a SIGINT signal within a function, the EXIT signal cannot be trapped when the shell exits.

The trap command with no arguments prints a list of commands associated with each signal number. If the command specified is NULL, indicated as "" (empty quotes), then the ksh command will ignore the signal. For more information about how the Korn shell or the POSIX shell reads a character as a regular character, see Quotation of characters in the Korn shell or POSIX shell.

For a complete list of Signal parameter values used in the trap command without the SIG prefix, see the sigaction, sigvec, or signal subroutine in the Technical Reference: Base Operating System and Extensions, Volume 2.

typeset [+HLRZfilrtux [n]] [Name[=Value]] ... Sets attributes and values for shell parameters. When invoked inside a function, a new instance of the Name parameter is created. The parameter value and type are restored when the function completes. You can specify the following flags with the typeset command:
-H
Provides AIX®-to-host-file mapping on non-AIX machines.
-L
Left-justifies and removes leading blanks from the Value parameter. If the n parameter has a nonzero value, it defines the width of the field; otherwise, it is determined by the width of the value of its first assignment. When the parameter is assigned, it is filled on the right with blanks or truncated, if necessary, to fit into the field. Leading zeros are removed if the -Z flag is also set. The -R flag is turned off.
-R
Right-justifies and fills with leading blanks. If the n parameter has a nonzero value, it defines the width of the field; otherwise, it is determined by the width of the value of its first assignment. The field remains filled with blanks or is truncated from the end if the parameter is reassigned. The L flag is turned off.
-Z
Right-justifies and fills with leading zeros if the first nonblank character is a digit and the -L flag has not been set. If the n parameter has a nonzero value, it defines the width of the field; otherwise, it is determined by the width of the value of its first assignment.
-f
Indicates that the names refer to function names rather than parameter names. No assignments can be made and the only other valid flags are -t, -u, and -x . The -t flag turns on execution tracing for this function. The -u flag causes this function to be marked undefined. The FPATH variable is searched to find the function definition when the function is referenced. The -x flag allows the function definition to remain in effect across shell scripts that are not a separate invocation of the ksh command.
-i
Identifies the parameter as an integer, making arithmetic faster. If the n parameter has a nonzero value, it defines the output arithmetic base; otherwise, the first assignment determines the output base.
-l
Converts all uppercase characters to lowercase. The -u uppercase conversion flag is turned off.
-r
Marks the names specified by the Name parameter as read-only. These names cannot be changed by subsequent assignment.
 
-t
Tags the named parameters. Tags can be defined by the user and have no special meaning to the shell.
-u
Converts all lowercase characters to uppercase characters. The -l lowercase flag is turned off.
-x
Marks the name specified by the Name parameter for automatic export to the environment of subsequently executed commands.

Using a + rather than a - turns off the typeset command flags. If you do not specify Name parameters but do specify flags, a list of names (and optionally the values) of the parameters that have these flags set is printed. (Using a + rather than a - keeps the values from being printed.) If you do not specify any names or flags, the names and attributes of all parameters are printed.

unset [-fv ] Name ... Unsets the values and attributes of the parameters given by the list of names. If -v is specified, Name refers to a variable name, and the shell will unset it and remove it from the environment. Read-only variables cannot be unset. Unsetting the ERRNO, LINENO, MAILCHECK, OPTARG, OPTIND, RANDOM, SECONDS, TMOUT, and underscore (_) variables removes their special meanings even if they are subsequently assigned.

If the -f flag is set, then Name refers to a function name, and the shell will unset the function definition.