[ Next Article | Previous Article | Book Contents | Library Home | Legal | Search ]
System User's Guide: Operating System and Devices

Korn Shell or POSIX Shell Built-In Commands

Special commands are built in to the Korn shell and POSIX shell and executed in the shell process. Unless otherwise indicated, the output is written to file descriptor 1 and the exit status is 0 (zero) if the command does not contain any syntax errors. Input and output redirection is permitted. There are two types of built-in commands, special built-in commands and regular built-in commands.

Refer to the List of Korn Shell or POSIX Shell Built-in Commands for an alphabetical listing of these commands.

Special built-in commands differ from regular built-in commands in the following ways:

In addition, words that are in the form of a parameter assignment following the export, readonly, and typeset special commands are expanded with the same rules as a parameter assignment. This means that tilde substitution is performed after the = (equal sign), and word splitting and file name substitution are not performed.

Special Built-in Command Descriptions

The Korn Shell provides the following special built-in commands:

:              eval            newgrp           shift
.              exec            readonly         times
break          exit            return           trap
continue       export          set              typeset
                                                unset
                                                
: [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 last command executed. Refer to 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 variable, 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 last 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 variable. If you omit the n variable, the return status is that of the last 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]... [+ |-A Name] [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, as described below. When arguments are specified, they will cause positional parameters to be set or unset, as described below. The flags for this command are interpreted 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 Exports automatically 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. 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 just 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 (refer to "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. Arguments, as specified by the Option variable, can be one of the following:
allexport Same as the -a flag.
errexit Same as the -e 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.
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 / (slash) 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 from being saved in the history file.
nounset Same as the -u flag.
privileged Same as the -p flag.
verbose Same as the -v flag.
trackall Same as the -h 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 since 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 a - (minus sign). If no arguments follow this flag, the positional parameters are not set.

Preceding any of the set command flags with a + (plus sign) rather than a - (minus sign) turns off the flag. You can use these flags when you invoke the shell. 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 forth. If no arguments are given, the names and values of all named parameters are printed to standard output.

shiftn [] 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.
trapCommandSignal [] [] ... 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 a - (minus sign), 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. The trap command with no arguments prints a list of commands associated with each signal number.

For a complete list of Signal parameter values, used in the trap command without the SIG prefix, refer to the sigaction, sigvec, or signal subroutine in the AIX Version 4.3 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, 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 + (plus sign) rather than a - (minus sign) 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.

Regular Built-in Command Descriptions

The Korn Shell provides the following regular built-in commands:

alias          fg            print          ulimit
bg             getopts       pwd            umask
cd             jobs          read           unalias
command        kill          setgroups      wait
echo           let           test           whence
fc
alias [-t ] [-x ] [AliasName[= String]] ... Creates or redefines alias definitions or writes existing alias definitions to standard output.

For more information, refer to the alias command in the AIX Version 4.3 Commands Reference.

bg [JobID...] Puts each specified job into the background. The current job is put in the background if a JobID parameter is not specified. Refer to "Job Control in the Korn Shell or POSIX Shell" for more information about job control.

For more information about running jobs in the background, refer to the bg command in the AIX Version 4.3 Commands Reference.

cd [Argument]  
cd Old New This command can be in either of two forms. In the first form, it changes the current directory to the one specified by the Argument parameter. If the value of the Argument parameter is - (minus sign), the directory is changed to the previous directory. The HOME shell variable is the default value of the Argument parameter. The PWD variable is set to the current directory.

The CDPATH shell variable defines the search path for the directory containing the value of the Argument parameter. Alternative directory names are separated by a : (colon). The default path is null, specifying the current directory. The current directory is specified by a null path name, which appears immediately after the equal sign or between the colon delimiters anywhere in the path list. If the specified argument begins with a / (slash), the search path is not used. Otherwise, each directory in the path is searched for the argument.

The second form of the cd command substitutes the string specified by the New variable for the string specified by the Old variable in the current directory name, PWD, and tries to change to this new directory.

command [-p ] CommandName [Argument ...]  
command [-v | -V ] CommandName Command causes the shell to treat the specified command and arguments as a simple command, suppressing shell function lookup.

For more information, refer to the command command in the AIX Version 4.3 Commands Reference.

echo [String ...] Writes character strings to standard output. Refer to the echo command for usage and description. The -n flag is not supported.
fc [-r ] [-e Editor] [First [Last]]  
fc -l [-n ] [-r ] [First [Last]]  
fc -s [Old= New] [First] Displays the contents of your command history file or invokes an editor to modify and re-executes commands previously entered in the shell.

For more information, refer to the fc command in the AIX Version 4.3 Commands Reference.

fg [JobID] Brings each job specified into the foreground. If you do not specify any jobs, the command brings the current job into the foreground.

For more information about running jobs in the foreground, refer to the fg command in the AIX Version 4.3 Commands Reference.

getopts OptionString Name [Argument ...] Checks the Argument parameter for legal options.

For more information, refer to the getopts command in the AIX Version 4.3 Commands Reference.

jobs [-l | -n | -p ] [JobID ...] Displays the status of jobs started in the current shell environment. If no specific job is specified with the JobID parameter, status information for all active jobs is displayed. If a job termination is reported, the shell removes that job's process ID from the list of those known by the current shell environment.

For more information, refer to the jobs command in the AIX Version 4.3 Commands Reference.

   
To Send Signal to Processes:  
kill [ -s { SignalName | SignalNumber } ] ProcessID...  
kill [ -SignalName | -SignalNumber ] ProcessID...  
   
To List Signal Names:  
kill -l [ ExitStatus ] Sends a signal (by default, the SIGTERM signal) to a running process. This default action normally stops processes. If you want to stop a process, specify the process ID (PID) in the ProcessID variable. The shell reports the PID of each process that is running in the background (unless you start more than one process in a pipeline, in which case the shell reports the number of the last process). You can also use the ps command to find the process ID number of commands.

For more information, refer to the kill command in the AIX Version 4.3 Commands Reference.

let Expression ... Evaluates specified arithmetic expressions. The exit status is 0 if the value of the last expression is nonzero, and 1 otherwise. Refer to "Arithmetic Evaluation in the Korn Shell or POSIX Shell" for more information.
print [-Rnprsu [n]] [Argument ...] Prints shell output. If you do not specify any flags, or if the - (minus sign) or -- (dash) flags are specified, the arguments are printed to standard output as described by the echo command. The flags do the following:
-R Prints in raw mode (the escape conventions of the echo command are ignored). The -R Flag prints all subsequent arguments and flags other than -n.
-n Prevents a new-line character from being added to the output.
-p Writes the arguments to the pipe of the process run with |& (bar, ampersand) instead of to standard output.
-r Prints in raw mode. The escape conventions of the echo command are ignored.
-s Writes the arguments to the history file instead of to standard output.
-u Specifies a one-digit file descriptor unit number, n, on which the output is placed. The default is 1.
pwd Equivalent to print -r - $PWD.
Note: The internal Korn shell pwd command does not support symbolic links.
read [-prsu [n ]] [Name?Prompt] [Name...] Takes shell input. One line is read and broken up into fields, using the characters in the IFS variable as separators.

For more information, refer to the read command in the AIX Version 4.3 Commands Reference.

setgroups Executes the /usr/bin/setgroups command, which runs as a separate shell. See the setgroups command for information on how this command works. There is one difference, however. The setgroups built-in command invokes a subshell, but the setgroups command replaces the currently executing shell. Since the built-in command is supported only for compatibility, it is recommended that scripts use the absolute path name /usr/bin/setgroups rather than the shell built-in command.
test Same as [expression]. See "Conditional Expressions" for usage and description.
ulimit [-HSacdfmst ] [Limit] Sets or displays user-process resource limits as defined in the /etc/security/limits file. This file contains six default limits:
fsize = 2097151
core = 2048
cpu = 3600
data = 131072
rss = 65536
stack = 8192

These values are used as default settings when a new user is added to the system. The values are set with the mkuser command when the user is added to the system, or changed with the chuser command.

Limits are categorized as either soft or hard. Users may change their soft limits, up to the maximum set by the hard limits, with the ulimit command. You must have root user authority to change resource hard limits.

Many systems do not contain one or more of these limits. The limit for a specified resource is set when the Limit parameter is specified. The value of the Limit parameter can be a number in the unit specified with each resource, or the value unlimited. You can specify the following ulimit command flags:

-H Specifies that the hard limit for the given resource is set. If you have root user authority, you can increase the hard limit. Anyone can decrease it.
-S Specifies that the soft limit for the given resource is set. A soft limit can be increased up to the value of the hard limit. If neither the -H or -S options are specified, the limit applies to both.
-a Lists all of the current resource limits.
-c Specifies the number of 512-byte blocks on the size of core dumps.
-d Specifies the size, in KB, of the data area.
-f Specifies the number of 512-byte blocks for files written by child processes (files of any size can be read).
-m Specifies the number of KB for the size of physical memory.
-n Specifies the limit on the number of file descriptors a process may have open.
-s Specifies the number of KB for the size of the stack area.
-t Specifies the number of seconds to be used by each process.

The current resource limit is printed when you omit the Limit variable. The soft limit is printed unless you specify the -H flag. When you specify more than one resource, the limit name and unit is printed before the value. If no option is given, the -f flag is assumed. When you change the value, set both hard and soft limits to Limit unless you specify -H or -S.

For more information about user and system resource limits, refer to the getrlimit, setrlimit, or vlimit subroutine in the AIX Version 4.3 Technical Reference: Base Operating System and Extensions Volume 1.

umask [-S ] [Mask] Determines file permissions. This value, along with the permissions of the creating process, determines a file's permissions when the file is created. The default is 022. If the Mask parameter is not specified, the umask command displays to standard output the file mode creation mask of the current shell environment.

For more information about file permissions, refer to the umask command in the AIX Version 4.3 Commands Reference.

unalias -a  
unalias AliasName... Removes the definition for each alias name specified, or removes all alias definitions if the -a flag is used. Alias definitions are removed from the current shell environment.

For more information, refer to the unalias command in the AIX Version 4.3 Commands Reference.

wait [ProcessID...] Waits for the specified job and terminates. If you do not specify a job, the command waits for all currently active child processes. The exit status from this command is that of the process for which it waits.

For more information, refer to the wait command in the AIX Version 4.3 Commands Reference.

whence [-pv ] Name ... Indicates, for each name specified, how it would be interpreted if used as a command name. When used without either flag, whence will display the absolute pathname, if any, that corresponds to each name.
-p Does a path search for the specified name or names even if these are aliases, functions, or reserved words.
-v Produces a more verbose report that specifies which type each name is.

[ Next Article | Previous Article | Book Contents | Library Home | Legal | Search ]