Special command descriptions

The Bourne shell provides the following special built-in commands.


Item Description
: Returns a zero exit value.
. File Reads and runs commands from the File parameter and returns. Does not start a subshell. The shell uses the search path specified by the PATH variable to find the directory containing the specified file.
break [ n ] Exits from the enclosing for, while, or until command loops, if any. If you specify the n variable, the break command breaks the number of levels specified by the n variable.
continue [ n ] Resumes the next iteration of the enclosing for, while, or until command loops. If you specify the n variable, the command resumes at the nth enclosing loop.
cd Directory ] Changes the current directory to Directory. If you do not specify Directory, the value of the HOME shell variable is used. The CDPATH shell variable defines the search path for Directory. CDPATH is a colon-separated list of alternative directory names. A null path name specifies the current directory (which is the default path). This null path name appears immediately after the equal sign in the assignment or between the colon delimiters anywhere else in the path list. If Directory begins with a slash (/), the shell does not use the search path. Otherwise, the shell searches each directory in the CDPATH shell variable.
Note: The restricted shell cannot run the cd shell command.
echo String . . . ] Writes character strings to standard output. See the echo command for usage and parameter information. The -n flag is not supported.
eval [ Argument . . . ] Reads arguments as input to the shell and runs the resulting command or commands.
exec [ Argument . . . ] Runs the command specified by the Argument parameter in place of this shell without creating a new process. Input and output arguments can appear, and if no other arguments appear, cause the shell input or output to be modified. This is not recommended for your login shell.
exit [ n ] Causes a shell to exit with the exit value specified by the n parameter. If you omit this parameter, the exit value is that of the last command executed (the Ctrl-D key sequence also causes a shell to exit). The value of the n parameter can be from 0 to 255, inclusive.
export [ Name . . . ] Marks the specified names for automatic export to the environments of subsequently executed commands. If you do not specify the Name parameter, the export command displays a list of all names that are exported in this shell. You cannot export function names.
hash [ -r ][ Command . . . ] Finds and remembers the location in the search path of each Command specified. The -r flag causes the shell to forget all locations. If you do not specify the flag or any commands, the shell displays information about the remembered commands in the following format:
Hits   Cost   Command
  Hits indicates the number of times a command has been run by the shell process. Cost is a measure of the work required to locate a command in the search path. Command shows the path names of each specified command. Certain situations require that the stored location of a command be recalculated; for example, the location of a relative path name when the current directory changes. Commands for which that might be done are indicated by an asterisk (*) next to the Hits information. Cost is incremented when the recalculation is done.
pwd Displays the current directory. See the pwd command for a discussion of command options.
read [ Name . . . ] Reads one line from standard input. Assigns the first word in the line to the first Name parameter, the second word to the second Name parameter, and so on, with leftover words assigned to the last Name parameter. This command returns a value of 0 unless it encounters an end-of-file character.
readonly [ Name . . . ] Marks the name specified by the Name parameter as read-only. The value of the name cannot be reset. If you do not specify any Name, the readonly command displays a list of all read-only names.
return [ n ] Causes a function to exit with a return value of n. If you do not specify the n variable, the function returns the status of the last command performed in that function. This command is valid only when run within a shell function.
set [ Flag [ Argument ] . . . ] Sets one or more of the following flags:
-a
Marks for export all variables to which an assignment is performed. If the assignment precedes a command name, the export attribute is effective only for that command execution environment, except when the assignment precedes one of the special built-in commands. In this case, the export attribute persists after the built-in command has completed. If the assignment does not precede a command name, or if the assignment is a result of the operation of the getopts or read commands, the export attribute persists until the variable is unset.
-e
Exits immediately if all of the following conditions exist for a command:
  • It exits with a return value greater than 0 (zero).
  • It is not part of the compound list of a while, until, or if command.
  • It is not being tested using AND or OR lists.
  • It is not a pipeline preceded by the ! (exclamation point) reserved word.
-f
Disables file name substitution.
-h
Locates and remembers the commands called within functions as the functions are defined. (Normally, these commands are located when the function is performed; see the hash command.)
-k
Places all keyword parameters in the environment for a command, not just those preceding the command name.
-n
Reads commands but does not run them. To check for shell script syntax errors, use the -n flag.
-t
Exits after reading and executing one command.
-u
Treats an unset variable as an error and immediately exits when performing variable substitution. An interactive shell does not exit.
-v
Displays shell input lines as they are read.
-x
Displays commands and their arguments before they are run.
Does not change any of the flags. This is useful in setting the $1 positional parameter to a string beginning with a hyphen (-).
 

Using a plus sign (+) rather than a hyphen (-) unsets flags. You can also specify these flags on the shell command line. The $- special variable contains the current set of flags.

Any Argument to the set command becomes a positional parameter and is assigned, in order, to $1, $2, ..., and so on. If you do not specify a flag or Argument, the set command displays all the names and values of the current shell variables.

shift [n] Shifts command line arguments to the left; that is, reassigns the value of the positional parameters by discarding the current value of $1 and assigning the value of $2 to $1, of $3 to $2, and so on. If there are more than 9 command line arguments, the 10th is assigned to $9 and any that remain are still unassigned (until after another shift). If there are 9 or fewer arguments, the shift command unsets the highest-numbered positional parameter that has a value.

The $0 positional parameter is never shifted. The shift n command is a shorthand notation specifying n number of consecutive shifts. The default value of the n parameter is 1.

test Expression | [ Expression ] Evaluates conditional expressions. See the test command for a discussion of command flags and parameters. The -h flag is not supported by the built-in test command in bsh.
times Displays the accumulated user and system times for processes run from the shell.
trap [ Command ] [ n ] . . .  Runs the command specified by the Command parameter when the shell receives the signal or signals specified by the n parameter. The trap commands are run 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.
Note: The shell scans the Command parameter once when the trap is set and again when the trap is taken.
If you do not specify a command, then all traps specified by the n parameter are reset to their current values. If you specify a null string, this signal is ignored by the shell and by the commands it invokes. If the n parameter is zero (0), the specified command is run when you exit from the shell. If you do not specify either a command or a signal, the trap command displays a list of commands associated with each signal number.
type [Name . . . ] Indicates how the shell would interpret it as a command name for each Name specified.
ulimit [-HS] [ -c | -d | -f | -m | -r | -s | -t |-u] [limit] Displays or adjusts allocated shell resources. The shell resource settings can be displayed either individually or as a group. The default mode is to display resources set to the soft setting, or the lower bound, as a group.

The setting of shell resources depends on the effective user ID of the current shell. The hard level of a resource can be set only if the effective user ID of the current shell is root. You will get an error if you are not root user and you are attempting to set the hard level of a resource. By default, the root user sets both the hard and soft limits of a particular resource. The root user should therefore be careful in using the -S, -H, or default flag usage of limit settings. Unless you are a root user, you can set only the soft limit of a resource. After a limit has been decreased by a nonroot user, it cannot be increased, even back to the original system limit.

To set a resource limit, select the appropriate flag and the limit value of the new resource, which should be an integer. You can set only one resource limit at a time. If more than one resource flag is specified, you receive undefined results. By default, ulimit with only a new value on the command line sets the file size of the shell. Use of the -f flag is optional.

You can specify the following ulimit command flags:

-c
Sets or displays core segment for shell.
-d
Sets or displays data segment for shell.
-f
Sets or displays file size for shell.
-H
Sets or displays hard resource limit (root user only).
-m
Sets or displays memory for shell.
-r
Sets or displays maximum number of threads per process.
-s
Sets or displays stack segment for shell.
-S
Sets or displays soft resource limit.
-t
Sets or displays CPU time maximum for shell.
-u
Sets or displays maximum number of processes per user.
umask [nnn] 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. When no value is entered, umask displays the current value.
unset [Name . . .] Removes the corresponding variable or function for each name specified by the Name parameter. The PATH, PS1, PS2, MAILCHECK, and IFS shell variables cannot be unset.
wait [n] Waits for the child process whose process number is specified by the n parameter to exit and then returns the exit status of that process. If you do not specify the n parameter, the shell waits for all currently active child processes, and the return value is 0.