Unless otherwise noted, each builtin command documented in this
section as accepting options preceded by
-
accepts
--
to signify the end of the options.
The :, true, false, and test builtins
do not accept options and do not treat -- specially.
The exit, logout, break, continue, let,
and shift builtins accept and process arguments beginning with
- without requiring --.
Other builtins that accept arguments but are not specified as accepting
options interpret arguments beginning with - as invalid options and
require -- to prevent this interpretation.
The return value is true unless an invalid option is supplied, an attempt
is made to modify the options for a name for which no completion
specification exists, or an output error occurs.
- continue [n]
-
Resume the next iteration of the enclosing
for,
while,
until,
or
select
loop.
If
n
is specified, resume at the nth enclosing loop.
n
must be ≥ 1. If
n
is greater than the number of enclosing loops, the last enclosing loop
(the ``top-level'' loop) is resumed.
The return value is 0 unless n is not greater than or equal to 1.
- declare [-aAfFilrtux] [-p] [name[=value] ...]
-
- typeset [-aAfFilrtux] [-p] [name[=value] ...]
-
Declare variables and/or give them attributes.
If no names are given then display the values of variables.
The
-p
option will display the attributes and values of each
name.
When
-p
is used with name arguments, additional options are ignored.
When
-p
is supplied without name arguments, it will display the attributes
and values of all variables having the attributes specified by the
additional options.
If no other options are supplied with -p, declare will display
the attributes and values of all shell variables. The -f option
will restrict the display to shell functions.
The
-F
option inhibits the display of function definitions; only the
function name and attributes are printed.
If the extdebug shell option is enabled using shopt,
the source file name and line number where the function is defined
are displayed as well. The
-F
option implies
-f.
The following options can
be used to restrict output to variables with the specified attribute or
to give variables attributes:
-
- -a
-
Each name is an indexed array variable (see
Arrays
above).
- -A
-
Each name is an associative array variable (see
Arrays
above).
- -f
-
Use function names only.
- -i
-
The variable is treated as an integer; arithmetic evaluation (see
ARITHMETIC EVALUATION
above) is performed when the variable is assigned a value.
- -l
-
When the variable is assigned a value, all upper-case characters are
converted to lower-case.
The upper-case attribute is disabled.
- -r
-
Make names readonly. These names cannot then be assigned values
by subsequent assignment statements or unset.
- -t
-
Give each name the trace attribute.
Traced functions inherit the DEBUG and RETURN traps from
the calling shell.
The trace attribute has no special meaning for variables.
- -u
-
When the variable is assigned a value, all lower-case characters are
converted to upper-case.
The lower-case attribute is disabled.
- -x
-
Mark names for export to subsequent commands via the environment.
Using `+' instead of `-'
turns off the attribute instead,
with the exceptions that +a
may not be used to destroy an array variable and +r will not
remove the readonly attribute.
When used in a function,
makes each
name local, as with the
local
command.
If a variable name is followed by =value, the value of
the variable is set to value.
The return value is 0 unless an invalid option is encountered,
an attempt is made to define a function using
``-f foo=bar'',
an attempt is made to assign a value to a readonly variable,
an attempt is made to assign a value to an array variable without
using the compound assignment syntax (see
Arrays
above), one of the names is not a valid shell variable name,
an attempt is made to turn off readonly status for a readonly variable,
an attempt is made to turn off array status for an array variable,
or an attempt is made to display a non-existent function with -f.
- dirs [+n] [-n] [-cplv]
-
Without options, displays the list of currently remembered directories.
The default display is on a single line with directory names separated
by spaces.
Directories are added to the list with the
pushd
command; the
popd
command removes entries from the list.
-
- +n
-
Displays the nth entry counting from the left of the list
shown by
dirs
when invoked without options, starting with zero.
- -n
-
Displays the nth entry counting from the right of the list
shown by
dirs
when invoked without options, starting with zero.
- -c
-
Clears the directory stack by deleting all of the entries.
- -l
-
Produces a longer listing; the default listing format uses a
tilde to denote the home directory.
- -p
-
Print the directory stack with one entry per line.
- -v
-
Print the directory stack with one entry per line,
prefixing each entry with its index in the stack.
The return value is 0 unless an
invalid option is supplied or n indexes beyond the end
of the directory stack.
- disown [-ar] [-h] [jobspec ...]
-
Without options, each
jobspec
is removed from the table of active jobs.
If
jobspec
is not present, and neither -a nor -r is supplied,
the shell's notion of the current job is used.
If the -h option is given, each
jobspec
is not removed from the table, but is marked so that
SIGHUP
is not sent to the job if the shell receives a
SIGHUP.
If no
jobspec
is present, and neither the
-a
nor the
-r
option is supplied, the current job is used.
If no
jobspec
is supplied, the
-a
option means to remove or mark all jobs; the
-r
option without a
jobspec
argument restricts operation to running jobs.
The return value is 0 unless a
jobspec
does not specify a valid job.
- echo [-neE] [arg ...]
-
Output the args, separated by spaces, followed by a newline.
The return status is always 0.
If -n is specified, the trailing newline is
suppressed. If the -e option is given, interpretation of
the following backslash-escaped characters is enabled. The
-E
option disables the interpretation of these escape characters,
even on systems where they are interpreted by default.
The xpg_echo shell option may be used to
dynamically determine whether or not echo expands these
escape characters by default.
echo
does not interpret -- to mean the end of options.
echo
interprets the following escape sequences:
-
- \a
-
alert (bell)
- \b
-
backspace
- \c
-
suppress further output
- \e
-
an escape character
- \f
-
form feed
- \n
-
new line
- \r
-
carriage return
- \t
-
horizontal tab
- \v
-
vertical tab
- \\
-
backslash
- \0nnn
-
the eight-bit character whose value is the octal value nnn
(zero to three octal digits)
- \xHH
-
the eight-bit character whose value is the hexadecimal value HH
(one or two hex digits)
- enable [-a] [-dnps] [-f filename] [name ...]
-
Enable and disable builtin shell commands.
Disabling a builtin allows a disk command which has the same name
as a shell builtin to be executed without specifying a full pathname,
even though the shell normally searches for builtins before disk commands.
If -n is used, each name
is disabled; otherwise,
names are enabled. For example, to use the
test
binary found via the
PATH
instead of the shell builtin version, run
``enable -n test''.
The
-f
option means to load the new builtin command
name
from shared object
filename,
on systems that support dynamic loading. The
-d
option will delete a builtin previously loaded with
-f.
If no name arguments are given, or if the
-p
option is supplied, a list of shell builtins is printed.
With no other option arguments, the list consists of all enabled
shell builtins.
If -n is supplied, only disabled builtins are printed.
If -a is supplied, the list printed includes all builtins, with an
indication of whether or not each is enabled.
If -s is supplied, the output is restricted to the POSIX
special builtins.
The return value is 0 unless a
name
is not a shell builtin or there is an error loading a new builtin
from a shared object.
- eval [arg ...]
-
The args are read and concatenated together into a single
command. This command is then read and executed by the shell, and
its exit status is returned as the value of
eval.
If there are no
args,
or only null arguments,
eval
returns 0.
- exec [-cl] [-a name] [command [arguments]]
-
If
command
is specified, it replaces the shell.
No new process is created. The
arguments
become the arguments to command.
If the
-l
option is supplied,
the shell places a dash at the beginning of the zeroth argument passed to
command.
This is what
login(1)
does. The
-c
option causes
command
to be executed with an empty environment. If
-a
is supplied, the shell passes
name
as the zeroth argument to the executed command. If
command
cannot be executed for some reason, a non-interactive shell exits,
unless the shell option
execfail
is enabled, in which case it returns failure.
An interactive shell returns failure if the file cannot be executed.
If
command
is not specified, any redirections take effect in the current shell,
and the return status is 0. If there is a redirection error, the
return status is 1.
- exit [n]
-
Cause the shell to exit
with a status of n. If
n
is omitted, the exit status
is that of the last command executed.
A trap on
EXIT
is executed before the shell terminates.
- export [-fn] [name[=word]] ...
-
- export -p
-
The supplied
names
are marked for automatic export to the environment of
subsequently executed commands. If the
-f
option is given,
the
names
refer to functions.
If no
names
are given, or if the
-p
option is supplied, a list
of all names that are exported in this shell is printed.
The
-n
option causes the export property to be removed from each
name.
If a variable name is followed by =word, the value of
the variable is set to word.
export
returns an exit status of 0 unless an invalid option is
encountered,
one of the names is not a valid shell variable name, or
-f
is supplied with a
name
that is not a function.
- fc [-e ename] [-lnr] [first] [last]
-
- fc -s [pat=rep] [cmd]
-
Fix Command. In the first form, a range of commands from
first
to
last
is selected from the history list.
First
and
last
may be specified as a string (to locate the last command beginning
with that string) or as a number (an index into the history list,
where a negative number is used as an offset from the current
command number). If
last
is not specified it is set to
the current command for listing (so that
``fc -l -10''
prints the last 10 commands) and to
first
otherwise.
If
first
is not specified it is set to the previous
command for editing and -16 for listing.
The
-n
option suppresses
the command numbers when listing. The
-r
option reverses the order of
the commands. If the
-l
option is given,
the commands are listed on
standard output. Otherwise, the editor given by
ename
is invoked
on a file containing those commands. If
ename
is not given, the
value of the
FCEDIT
variable is used, and
the value of
EDITOR
if
FCEDIT
is not set. If neither variable is set,
is used. When editing is complete, the edited commands are
echoed and executed.
In the second form, command is re-executed after each instance
of pat is replaced by rep.
A useful alias to use with this is
``r="fc -s"'',
so that typing
``r cc''
runs the last command beginning with
``cc''
and typing
``r''
re-executes the last command.
If the first form is used, the return value is 0 unless an invalid
option is encountered or
first
or
last
specify history lines out of range.
If the
-e
option is supplied, the return value is the value of the last
command executed or failure if an error occurs with the temporary
file of commands. If the second form is used, the return status
is that of the command re-executed, unless
cmd
does not specify a valid history line, in which case
fc
returns failure.
- fg [jobspec]
-
Resume
jobspec
in the foreground, and make it the current job.
If
jobspec
is not present, the shell's notion of the current job is used.
The return value is that of the command placed into the foreground,
or failure if run when job control is disabled or, when run with
job control enabled, if
jobspec
does not specify a valid job or
jobspec
specifies a job that was started without job control.
- getopts optstring name [args]
-
getopts
is used by shell procedures to parse positional parameters.
optstring
contains the option characters to be recognized; if a character
is followed by a colon, the option is expected to have an
argument, which should be separated from it by white space.
The colon and question mark characters may not be used as
option characters.
Each time it is invoked,
getopts
places the next option in the shell variable
name,
initializing
name
if it does not exist,
and the index of the next argument to be processed into the
variable
OPTIND.
OPTIND
is initialized to 1 each time the shell or a shell script
is invoked. When an option requires an argument,
getopts
places that argument into the variable
OPTARG.
The shell does not reset
OPTIND
automatically; it must be manually reset between multiple
calls to
getopts
within the same shell invocation if a new set of parameters
is to be used.
When the end of options is encountered, getopts exits with a
return value greater than zero.
OPTIND
is set to the index of the first non-option argument,
and name is set to ?.
getopts
normally parses the positional parameters, but if more arguments are
given in
args,
getopts
parses those instead.
getopts
can report errors in two ways. If the first character of
optstring
is a colon,
silent
error reporting is used. In normal operation diagnostic messages
are printed when invalid options or missing option arguments are
encountered.
If the variable
OPTERR
is set to 0, no error messages will be displayed, even if the first
character of
optstring
is not a colon.
If an invalid option is seen,
getopts
places ? into
name
and, if not silent,
prints an error message and unsets
OPTARG.
If
getopts
is silent,
the option character found is placed in
OPTARG
and no diagnostic message is printed.
If a required argument is not found, and
getopts
is not silent,
a question mark (?) is placed in
name,
OPTARG
is unset, and a diagnostic message is printed.
If
getopts
is silent, then a colon (:) is placed in
name
and
OPTARG
is set to the option character found.
getopts
returns true if an option, specified or unspecified, is found.
It returns false if the end of options is encountered or an
error occurs.
- hash [-lr] [-p filename] [-dt] [name]
-
For each
name,
the full file name of the command is determined by searching
the directories in
$PATH
and remembered.
If the
-p
option is supplied, no path search is performed, and
filename
is used as the full file name of the command.
The
-r
option causes the shell to forget all
remembered locations.
The
-d
option causes the shell to forget the remembered location of each name.
If the
-t
option is supplied, the full pathname to which each name corresponds
is printed. If multiple name arguments are supplied with -t,
the name is printed before the hashed full pathname.
The
-l
option causes output to be displayed in a format that may be reused as input.
If no arguments are given, or if only -l is supplied,
information about remembered commands is printed.
The return status is true unless a
name
is not found or an invalid option is supplied.
- help [-dms] [pattern]
-
Display helpful information about builtin commands. If
pattern
is specified,
help
gives detailed help on all commands matching
pattern;
otherwise help for all the builtins and shell control structures
is printed.
-
- -d
-
Display a short description of each pattern
- -m
-
Display the description of each pattern in a manpage-like format
- -s
-
Display only a short usage synopsis for each pattern
The return status is 0 unless no command matches
pattern.
- history [n]
-
- history -c
-
- history -d offset
-
- history -anrw [filename]
-
- history -p arg [arg ...]
-
- history -s arg [arg ...]
-
With no options, display the command
history list with line numbers. Lines listed
with a
*
have been modified. An argument of
n
lists only the last
n
lines.
If the shell variable
HISTTIMEFORMAT
is set and not null,
it is used as a format string for strftime(3) to display
the time stamp associated with each displayed history entry.
No intervening blank is printed between the formatted time stamp
and the history line.
If filename is supplied, it is used as the
name of the history file; if not, the value of
HISTFILE
is used. Options, if supplied, have the following meanings:
-
- -c
-
Clear the history list by deleting all the entries.
- -d offset
-
Delete the history entry at position offset.
- -a
-
Append the ``new'' history lines (history lines entered since the
beginning of the current bash session) to the history file.
- -n
-
Read the history lines not already read from the history
file into the current history list. These are lines
appended to the history file since the beginning of the
current bash session.
- -r
-
Read the contents of the history file
and use them as the current history.
- -w
-
Write the current history to the history file, overwriting the
history file's contents.
- -p
-
Perform history substitution on the following args and display
the result on the standard output.
Does not store the results in the history list.
Each arg must be quoted to disable normal history expansion.
- -s
-
Store the
args
in the history list as a single entry. The last command in the
history list is removed before the
args
are added.
If the
HISTTIMEFORMAT
variable is set, the time stamp information
associated with each history entry is written to the history file,
marked with the history comment character.
When the history file is read, lines beginning with the history
comment character followed immediately by a digit are interpreted
as timestamps for the previous history line.
The return value is 0 unless an invalid option is encountered, an
error occurs while reading or writing the history file, an invalid
offset is supplied as an argument to -d, or the
history expansion supplied as an argument to -p fails.
- jobs [-lnprs] [ jobspec ... ]
-
- jobs -x command [ args ... ]
-
The first form lists the active jobs. The options have the following
meanings:
-
- -l
-
List process IDs
in addition to the normal information.
- -p
-
List only the process ID of the job's process group
leader.
- -n
-
Display information only about jobs that have changed status since
the user was last notified of their status.
- -r
-
Restrict output to running jobs.
- -s
-
Restrict output to stopped jobs.
If
jobspec
is given, output is restricted to information about that job.
The return status is 0 unless an invalid option is encountered
or an invalid
jobspec
is supplied.
If the
-x
option is supplied,
jobs
replaces any
jobspec
found in
command
or
args
with the corresponding process group ID, and executes
command
passing it
args,
returning its exit status.
- kill [-s sigspec | -n signum | -sigspec] [pid | jobspec] ...
-
- kill -l [sigspec | exit_status]
-
Send the signal named by
sigspec
or
signum
to the processes named by
pid
or
jobspec.
sigspec
is either a case-insensitive signal name such as
SIGKILL
(with or without the
SIG
prefix) or a signal number;
signum
is a signal number.
If
sigspec
is not present, then
SIGTERM
is assumed.
An argument of
-l
lists the signal names.
If any arguments are supplied when
-l
is given, the names of the signals corresponding to the arguments are
listed, and the return status is 0.
The exit_status argument to
-l
is a number specifying either a signal number or the exit status of
a process terminated by a signal.
kill
returns true if at least one signal was successfully sent, or false
if an error occurs or an invalid option is encountered.
- let arg [arg ...]
-
Each
arg
is an arithmetic expression to be evaluated (see
ARITHMETIC EVALUATION
above).
If the last
arg
evaluates to 0,
let
returns 1; 0 is returned otherwise.
- local [option] [name[=value] ...]
-
For each argument, a local variable named
name
is created, and assigned
value.
The option can be any of the options accepted by declare.
When
local
is used within a function, it causes the variable
name
to have a visible scope restricted to that function and its children.
With no operands,
local
writes a list of local variables to the standard output. It is
an error to use
local
when not within a function. The return status is 0 unless
local
is used outside a function, an invalid
name
is supplied, or
name is a readonly variable.
- logout
-
Exit a login shell.
- mapfile [-n count] [-O origin] [-s count] [-t] [-u fd] [-C callback] [-c quantum] [array]
-
- readarray [-n count] [-O origin] [-s count] [-t] [-u fd] [-C callback] [-c quantum] [array]
-
Read lines from the standard input into the indexed array variable
array,
or from file descriptor
fd
if the
-u
option is supplied.
The variable
MAPFILE
is the default array.
Options, if supplied, have the following meanings:
-
- -n
-
Copy at most
count
lines. If count is 0, all lines are copied.
- -O
-
Begin assigning to
array
at index
origin.
The default index is 0.
- -s
-
Discard the first count lines read.
- -t
-
Remove a trailing newline from each line read.
- -u
-
Read lines from file descriptor fd instead of the standard input.
- -C
-
Evaluate
callback
each time quantum lines are read. The -c option specifies
quantum.
- -c
-
Specify the number of lines read between each call to
callback.
If
-C
is specified without
-c,
the default quantum is 5000.
When callback is evaluated, it is supplied the index of the next
array element to be assigned as an additional argument.
callback is evaluated after the line is read but before the
array element is assigned.
If not supplied with an explicit origin, mapfile will clear array
before assigning to it.
mapfile returns successfully unless an invalid option or option
argument is supplied, array is invalid or unassignable, or if
array is not an indexed array.
- popd [-n] [+n] [-n]
-
Removes entries from the directory stack. With no arguments,
removes the top directory from the stack, and performs a
cd
to the new top directory.
Arguments, if supplied, have the following meanings:
-
- -n
-
Suppresses the normal change of directory when removing directories
from the stack, so that only the stack is manipulated.
- +n
-
Removes the nth entry counting from the left of the list
shown by
dirs,
starting with zero. For example:
``popd +0''
removes the first directory,
``popd +1''
the second.
- -n
-
Removes the nth entry counting from the right of the list
shown by
dirs,
starting with zero. For example:
``popd -0''
removes the last directory,
``popd -1''
the next to last.
If the
popd
command is successful, a
dirs
is performed as well, and the return status is 0.
popd
returns false if an invalid option is encountered, the directory stack
is empty, a non-existent directory stack entry is specified, or the
directory change fails.
- printf [-v var] format [arguments]
-
Write the formatted arguments to the standard output under the
control of the format.
The format is a character string which contains three types of objects:
plain characters, which are simply copied to standard output, character
escape sequences, which are converted and copied to the standard output, and
format specifications, each of which causes printing of the next successive
argument.
In addition to the standard printf(1) formats, %b causes
printf to expand backslash escape sequences in the corresponding
argument (except that \c terminates output, backslashes in
\', \", and \? are not removed, and octal escapes
beginning with \0 may contain up to four digits),
and %q causes printf to output the corresponding
argument in a format that can be reused as shell input.
The -v option causes the output to be assigned to the variable
var rather than being printed to the standard output.
The format is reused as necessary to consume all of the arguments.
If the format requires more arguments than are supplied, the
extra format specifications behave as if a zero value or null string, as
appropriate, had been supplied. The return value is zero on success,
non-zero on failure.
- pushd [-n] [+n] [-n]
-
- pushd [-n] [dir]
-
Adds a directory to the top of the directory stack, or rotates
the stack, making the new top of the stack the current working
directory. With no arguments, exchanges the top two directories
and returns 0, unless the directory stack is empty.
Arguments, if supplied, have the following meanings:
-
- -n
-
Suppresses the normal change of directory when adding directories
to the stack, so that only the stack is manipulated.
- +n
-
Rotates the stack so that the nth directory
(counting from the left of the list shown by
dirs,
starting with zero)
is at the top.
- -n
-
Rotates the stack so that the nth directory
(counting from the right of the list shown by
dirs,
starting with zero) is at the top.
- dir
-
Adds
dir
to the directory stack at the top, making it the
new current working directory.
If the
pushd
command is successful, a
dirs
is performed as well.
If the first form is used,
pushd
returns 0 unless the cd to
dir
fails. With the second form,
pushd
returns 0 unless the directory stack is empty,
a non-existent directory stack element is specified,
or the directory change to the specified new current directory
fails.
- pwd [-LP]
-
Print the absolute pathname of the current working directory.
The pathname printed contains no symbolic links if the
-P
option is supplied or the
-o physical
option to the
set
builtin command is enabled.
If the
-L
option is used, the pathname printed may contain symbolic links.
The return status is 0 unless an error occurs while
reading the name of the current directory or an
invalid option is supplied.
- read [-ers] [-a aname] [-d delim] [-i text] [-n nchars] [-N nchars] [-p prompt] [-t timeout] [-u fd] [name ...]
-
One line is read from the standard input, or from the file descriptor
fd supplied as an argument to the -u option, and the first word
is assigned to the first
name,
the second word to the second
name,
and so on, with leftover words and their intervening separators assigned
to the last
name.
If there are fewer words read from the input stream than names,
the remaining names are assigned empty values.
The characters in
IFS
are used to split the line into words.
The backslash character (\) may be used to remove any special
meaning for the next character read and for line continuation.
Options, if supplied, have the following meanings:
-
- -a aname
-
The words are assigned to sequential indices
of the array variable
aname,
starting at 0.
aname
is unset before any new values are assigned.
Other name arguments are ignored.
- -d delim
-
The first character of delim is used to terminate the input line,
rather than newline.
- -e
-
If the standard input
is coming from a terminal,
readline
(see
READLINE
above) is used to obtain the line.
Readline uses the current (or default, if line editing was not previously
active) editing settings.
- -i text
-
If
readline
is being used to read the line, text is placed into the editing
buffer before editing begins.
- -n nchars
-
read returns after reading nchars characters rather than
waiting for a complete line of input, but honor a delimiter if fewer
than nchars characters are read before the delimiter.
- -N nchars
-
read returns after reading exactly nchars characters rather
than waiting for a complete line of input, unless EOF is encountered or
read times out.
Delimiter characters encountered in the input are
not treated specially and do not cause read to return until
nchars characters are read.
- -p prompt
-
Display prompt on standard error, without a
trailing newline, before attempting to read any input. The prompt
is displayed only if input is coming from a terminal.
- -r
-
Backslash does not act as an escape character.
The backslash is considered to be part of the line.
In particular, a backslash-newline pair may not be used as a line
continuation.
- -s
-
Silent mode. If input is coming from a terminal, characters are
not echoed.
- -t timeout
-
Cause read to time out and return failure if a complete line of
input is not read within timeout seconds.
timeout may be a decimal number with a fractional portion following
the decimal point.
This option is only effective if read is reading input from a
terminal, pipe, or other special file; it has no effect when reading
from regular files.
If timeout is 0, read returns success if input is available on
the specified file descriptor, failure otherwise.
The exit status is greater than 128 if the timeout is exceeded.
- -u fd
-
Read input from file descriptor fd.
If no
names
are supplied, the line read is assigned to the variable
REPLY.
The return code is zero, unless end-of-file is encountered, read
times out (in which case the return code is greater than 128), or an
invalid file descriptor is supplied as the argument to -u.
- readonly [-aApf] [name[=word] ...]
-
The given
names are marked readonly; the values of these
names
may not be changed by subsequent assignment.
If the
-f
option is supplied, the functions corresponding to the
names are so
marked.
The
-a
option restricts the variables to indexed arrays; the
-A
option restricts the variables to associative arrays.
If no
name
arguments are given, or if the
-p
option is supplied, a list of all readonly names is printed.
The
-p
option causes output to be displayed in a format that
may be reused as input.
If a variable name is followed by =word, the value of
the variable is set to word.
The return status is 0 unless an invalid option is encountered,
one of the
names
is not a valid shell variable name, or
-f
is supplied with a
name
that is not a function.
- return [n]
-
Causes a function to exit with the return value specified by
n.
If
n
is omitted, the return status is that of the last command
executed in the function body. If used outside a function,
but during execution of a script by the
.
(source) command, it causes the shell to stop executing
that script and return either
n
or the exit status of the last command executed within the
script as the exit status of the script. If used outside a
function and not during execution of a script by .,
the return status is false.
Any command associated with the RETURN trap is executed
before execution resumes after the function or script.
- set [--abefhkmnptuvxBCEHPT] [-o option] [arg ...]
-
- set [+abefhkmnptuvxBCEHPT] [+o option] [arg ...]
-
Without options, the name and value of each shell variable are displayed
in a format that can be reused as input
for setting or resetting the currently-set variables.
Read-only variables cannot be reset.
In posix mode, only shell variables are listed.
The output is sorted according to the current locale.
When options are specified, they set or unset shell attributes.
Any arguments remaining after option processing are treated
as values for the positional parameters and are assigned, in order, to
$1,
$2,
...
$n.
Options, if specified, have the following meanings:
-
- -a
-
Automatically mark variables and functions which are modified or
created for export to the environment of subsequent commands.
- -b
-
Report the status of terminated background jobs
immediately, rather than before the next primary prompt. This is
effective only when job control is enabled.
- -e
-
Exit immediately if a pipeline (which may consist of a single
simple command), a subshell command enclosed in parentheses,
or one of the commands executed as part of a command list enclosed
by braces (see
SHELL GRAMMAR
above) exits with a non-zero status.
The shell does not exit if the
command that fails is part of the command list immediately following a
while
or
until
keyword,
part of the test following the
if
or
elif
reserved words, part of any command executed in a
&&
or
||
list except the command following the final && or ||,
any command in a pipeline but the last,
or if the command's return value is
being inverted with
!.
A trap on ERR, if set, is executed before the shell exits.
This option applies to the shell environment and each subshell environment
separately (see
COMMAND EXECUTION ENVIRONMENT
above), and may cause
subshells to exit before executing all the commands in the subshell.
- -f
-
Disable pathname expansion.
- -h
-
Remember the location of commands as they are looked up for execution.
This is enabled by default.
- -k
-
All arguments in the form of assignment statements
are placed in the environment for a command, not just
those that precede the command name.
- -m
-
Monitor mode. Job control is enabled. This option is on
by default for interactive shells on systems that support
it (see
JOB CONTROL
above). Background processes run in a separate process
group and a line containing their exit status is printed
upon their completion.
- -n
-
Read commands but do not execute them. This may be used to
check a shell script for syntax errors. This is ignored by
interactive shells.
- -o option-name
-
The option-name can be one of the following:
-
- allexport
-
Same as
-a.
- braceexpand
-
Same as
-B.
- emacs
-
Use an emacs-style command line editing interface. This is enabled
by default when the shell is interactive, unless the shell is started
with the
--noediting
option.
This also affects the editing interface used for read -e.
- errexit
-
Same as
-e.
- errtrace
-
Same as
-E.
- functrace
-
Same as
-T.
- hashall
-
Same as
-h.
- histexpand
-
Same as
-H.
- history
-
Enable command history, as described above under
HISTORY.
This option is on by default in interactive shells.
- ignoreeof
-
The effect is as if the shell command
``IGNOREEOF=10''
had been executed
(see
Shell Variables
above).
- keyword
-
Same as
-k.
- monitor
-
Same as
-m.
- noclobber
-
Same as
-C.
- noexec
-
Same as
-n.
- noglob
-
Same as
-f.
- nolog
-
Currently ignored.
- notify
-
Same as
-b.
- nounset
-
Same as
-u.
- onecmd
-
Same as
-t.
- physical
-
Same as
-P.
- pipefail
-
If set, the return value of a pipeline is the value of the last
(rightmost) command to exit with a non-zero status, or zero if all
commands in the pipeline exit successfully.
This option is disabled by default.
- posix
-
Change the behavior of
bash
where the default operation differs
from the POSIX standard to match the standard (posix mode).
- privileged
-
Same as
-p.
- verbose
-
Same as
-v.
- vi
-
Use a vi-style command line editing interface.
This also affects the editing interface used for read -e.
- xtrace
-
Same as
-x.
If
-o
is supplied with no option-name, the values of the current options are
printed.
If
+o
is supplied with no option-name, a series of
set
commands to recreate the current option settings is displayed on
the standard output.
- -p
-
Turn on
privileged
mode. In this mode, the
$ENV
and
$BASH_ENV
files are not processed, shell functions are not inherited from the
environment, and the
SHELLOPTS,
BASHOPTS,
CDPATH,
and
GLOBIGNORE
variables, if they appear in the environment, are ignored.
If the shell is started with the effective user (group) id not equal to the
real user (group) id, and the -p option is not supplied, these actions
are taken and the effective user id is set to the real user id.
If the -p option is supplied at startup, the effective user id is
not reset.
Turning this option off causes the effective user
and group ids to be set to the real user and group ids.
- -t
-
Exit after reading and executing one command.
- -u
-
Treat unset variables and parameters other than the special
parameters "@" and "*" as an error when performing
parameter expansion. If expansion is attempted on an
unset variable or parameter, the shell prints an error message, and,
if not interactive, exits with a non-zero status.
- -v
-
Print shell input lines as they are read.
- -x
-
After expanding each simple command,
for command, case command, select command, or
arithmetic for command, display the expanded value of
PS4,
followed by the command and its expanded arguments
or associated word list.
- -B
-
The shell performs brace expansion (see
Brace Expansion
above). This is on by default.
- -C
-
If set,
bash
does not overwrite an existing file with the
>,
>&,
and
<>
redirection operators. This may be overridden when
creating output files by using the redirection operator
>|
instead of
>.
- -E
-
If set, any trap on ERR is inherited by shell functions, command
substitutions, and commands executed in a subshell environment.
The ERR trap is normally not inherited in such cases.
- -H
-
Enable
!
style history substitution. This option is on by
default when the shell is interactive.
- -P
-
If set, the shell does not follow symbolic links when executing
commands such as
cd
that change the current working directory. It uses the
physical directory structure instead. By default,
bash
follows the logical chain of directories when performing commands
which change the current directory.
- -T
-
If set, any traps on DEBUG and RETURN are inherited by shell
functions, command substitutions, and commands executed in a
subshell environment.
The DEBUG and RETURN traps are normally not inherited
in such cases.
- --
-
If no arguments follow this option, then the positional parameters are
unset. Otherwise, the positional parameters are set to the
args, even if some of them begin with a
-.
- -
-
Signal the end of options, cause all remaining args to be
assigned to the positional parameters. The
-x
and
-v
options are turned off.
If there are no args,
the positional parameters remain unchanged.
The options are off by default unless otherwise noted.
Using + rather than - causes these options to be turned off.
The options can also be specified as arguments to an invocation of
the shell.
The current set of options may be found in
$-.
The return status is always true unless an invalid option is encountered.
- shift [n]
-
The positional parameters from n+1 ... are renamed to
$1
....
Parameters represented by the numbers $#
down to $#-n+1 are unset.
n
must be a non-negative number less than or equal to $#.
If
n
is 0, no parameters are changed.
If
n
is not given, it is assumed to be 1.
If
n
is greater than $#, the positional parameters are not changed.
The return status is greater than zero if
n
is greater than
$#
or less than zero; otherwise 0.
- shopt [-pqsu] [-o] [optname ...]
-
Toggle the values of variables controlling optional shell behavior.
With no options, or with the
-p
option, a list of all settable options is displayed, with
an indication of whether or not each is set.
The -p option causes output to be displayed in a form that
may be reused as input.
Other options have the following meanings:
-
- -s
-
Enable (set) each optname.
- -u
-
Disable (unset) each optname.
- -q
-
Suppresses normal output (quiet mode); the return status indicates
whether the optname is set or unset.
If multiple optname arguments are given with
-q,
the return status is zero if all optnames are enabled; non-zero
otherwise.
- -o
-
Restricts the values of optname to be those defined for the
-o
option to the
set
builtin.
If either
-s
or
-u
is used with no optname arguments, the display is limited to
those options which are set or unset, respectively.
Unless otherwise noted, the shopt options are disabled (unset)
by default.
The return status when listing options is zero if all optnames
are enabled, non-zero otherwise. When setting or unsetting options,
the return status is zero unless an optname is not a valid shell
option.
The list of shopt options is:
- autocd
-
If set, a command name that is the name of a directory is executed as if
it were the argument to the cd command.
This option is only used by interactive shells.
- cdable_vars
-
If set, an argument to the
cd
builtin command that
is not a directory is assumed to be the name of a variable whose
value is the directory to change to.
- cdspell
-
If set, minor errors in the spelling of a directory component in a
cd
command will be corrected.
The errors checked for are transposed characters,
a missing character, and one character too many.
If a correction is found, the corrected file name is printed,
and the command proceeds.
This option is only used by interactive shells.
- checkhash
-
If set, bash checks that a command found in the hash
table exists before trying to execute it. If a hashed command no
longer exists, a normal path search is performed.
- checkjobs
-
If set, bash lists the status of any stopped and running jobs before
exiting an interactive shell. If any jobs are running, this causes
the exit to be deferred until a second exit is attempted without an
intervening command (see
JOB CONTROL
above). The shell always
postpones exiting if any jobs are stopped.
- checkwinsize
-
If set, bash checks the window size after each command
and, if necessary, updates the values of
LINES
and
COLUMNS.
- cmdhist
-
If set,
bash
attempts to save all lines of a multiple-line
command in the same history entry. This allows
easy re-editing of multi-line commands.
- compat31
-
If set,
bash
changes its behavior to that of version 3.1 with respect to quoted
arguments to the conditional command's =~ operator.
- compat32
-
If set,
bash
changes its behavior to that of version 3.2 with respect to locale-specific
string comparison when using the conditional command's < and > operators.
- compat40
-
If set,
bash
changes its behavior to that of version 4.0 with respect to locale-specific
string comparison when using the conditional command's < and > operators
and the effect of interrupting a command list.
- dirspell
-
If set,
bash
attempts spelling correction on directory names during word completion
if the directory name initially supplied does not exist.
- dotglob
-
If set,
bash
includes filenames beginning with a `.' in the results of pathname
expansion.
- execfail
-
If set, a non-interactive shell will not exit if
it cannot execute the file specified as an argument to the
exec
builtin command. An interactive shell does not exit if
exec
fails.
- expand_aliases
-
If set, aliases are expanded as described above under
ALIASES.
This option is enabled by default for interactive shells.
- extdebug
-
If set, behavior intended for use by debuggers is enabled:
-
- 1.
-
The -F option to the declare builtin displays the source
file name and line number corresponding to each function name supplied
as an argument.
- 2.
-
If the command run by the DEBUG trap returns a non-zero value, the
next command is skipped and not executed.
- 3.
-
If the command run by the DEBUG trap returns a value of 2, and the
shell is executing in a subroutine (a shell function or a shell script
executed by the . or source builtins), a call to
return is simulated.
- 4.
-
BASH_ARGC
and
BASH_ARGV
are updated as described in their descriptions above.
- 5.
-
Function tracing is enabled: command substitution, shell functions, and
subshells invoked with ( command ) inherit the
DEBUG and RETURN traps.
- 6.
-
Error tracing is enabled: command substitution, shell functions, and
subshells invoked with ( command ) inherit the
ERROR trap.
- extglob
-
If set, the extended pattern matching features described above under
Pathname Expansion are enabled.
- extquote
-
If set, $'string' and $"string" quoting is
performed within ${parameter} expansions
enclosed in double quotes. This option is enabled by default.
- failglob
-
If set, patterns which fail to match filenames during pathname expansion
result in an expansion error.
- force_fignore
-
If set, the suffixes specified by the
FIGNORE
shell variable
cause words to be ignored when performing word completion even if
the ignored words are the only possible completions.
See
SHELL VARIABLES
above for a description of
FIGNORE.
This option is enabled by default.
- globstar
-
If set, the pattern ** used in a pathname expansion context will
match a files and zero or more directories and subdirectories.
If the pattern is followed by a /, only directories and
subdirectories match.
- gnu_errfmt
-
If set, shell error messages are written in the standard GNU error
message format.
- histappend
-
If set, the history list is appended to the file named by the value
of the
HISTFILE
variable when the shell exits, rather than overwriting the file.
- histreedit
-
If set, and
readline
is being used, a user is given the opportunity to re-edit a
failed history substitution.
- histverify
-
If set, and
readline
is being used, the results of history substitution are not immediately
passed to the shell parser. Instead, the resulting line is loaded into
the readline editing buffer, allowing further modification.
- hostcomplete
-
If set, and
readline
is being used, bash will attempt to perform hostname completion when a
word containing a @ is being completed (see
Completing
under
READLINE
above).
This is enabled by default.
- huponexit
-
If set, bash will send
SIGHUP
to all jobs when an interactive login shell exits.
- interactive_comments
-
If set, allow a word beginning with
#
to cause that word and all remaining characters on that
line to be ignored in an interactive shell (see
COMMENTS
above). This option is enabled by default.
- lithist
-
If set, and the
cmdhist
option is enabled, multi-line commands are saved to the history with
embedded newlines rather than using semicolon separators where possible.
- login_shell
-
The shell sets this option if it is started as a login shell (see
INVOCATION
above).
The value may not be changed.
- mailwarn
-
If set, and a file that bash is checking for mail has been
accessed since the last time it was checked, the message ``The mail in
mailfile has been read'' is displayed.
- no_empty_cmd_completion
-
If set, and
readline
is being used,
bash
will not attempt to search the
PATH
for possible completions when
completion is attempted on an empty line.
- nocaseglob
-
If set,
bash
matches filenames in a case-insensitive fashion when performing pathname
expansion (see
Pathname Expansion
above).
- nocasematch
-
If set,
bash
matches patterns in a case-insensitive fashion when performing matching
while executing case or [[ conditional commands.
- nullglob
-
If set,
bash
allows patterns which match no
files (see
Pathname Expansion
above)
to expand to a null string, rather than themselves.
- progcomp
-
If set, the programmable completion facilities (see
Programmable Completion above) are enabled.
This option is enabled by default.
- promptvars
-
If set, prompt strings undergo
parameter expansion, command substitution, arithmetic
expansion, and quote removal after being expanded as described in
PROMPTING
above. This option is enabled by default.
- restricted_shell
-
The shell sets this option if it is started in restricted mode (see
RESTRICTED SHELL
below).
The value may not be changed.
This is not reset when the startup files are executed, allowing
the startup files to discover whether or not a shell is restricted.
- shift_verbose
-
If set, the
shift
builtin prints an error message when the shift count exceeds the
number of positional parameters.
- sourcepath
-
If set, the
source (.) builtin uses the value of
PATH
to find the directory containing the file supplied as an argument.
This option is enabled by default.
- xpg_echo
-
If set, the echo builtin expands backslash-escape sequences
by default.
- suspend [-f]
-
Suspend the execution of this shell until it receives a
SIGCONT
signal. A login shell cannot be suspended; the
-f
option can be used to override this and force the suspension.
The return status is 0 unless the shell is a login shell and
-f
is not supplied, or if job control is not enabled.
- test expr
-
- [ expr ]
-
Return a status of 0 or 1 depending on
the evaluation of the conditional expression
expr.
Each operator and operand must be a separate argument.
Expressions are composed of the primaries described above under
CONDITIONALEXPRESSIONS.
test does not accept any options, nor does it accept and ignore
an argument of -- as signifying the end of options.
Expressions may be combined using the following operators, listed
in decreasing order of precedence.
The evaluation depends on the number of arguments; see below.
-
- ! expr
-
True if
expr
is false.
- ( expr )
-
Returns the value of expr.
This may be used to override the normal precedence of operators.
- expr1 -a expr2
-
True if both
expr1
and
expr2
are true.
- expr1 -o expr2
-
True if either
expr1
or
expr2
is true.
test and [ evaluate conditional
expressions using a set of rules based on the number of arguments.
- 0 arguments
-
The expression is false.
- 1 argument
-
The expression is true if and only if the argument is not null.
- 2 arguments
-
If the first argument is !, the expression is true if and
only if the second argument is null.
If the first argument is one of the unary conditional operators listed above
under
CONDITIONALEXPRESSIONS,
the expression is true if the unary test is true.
If the first argument is not a valid unary conditional operator, the expression
is false.
- 3 arguments
-
If the second argument is one of the binary conditional operators listed above
under
CONDITIONALEXPRESSIONS,
the result of the expression is the result of the binary test using
the first and third arguments as operands.
The -a and -o operators are considered binary operators
when there are three arguments.
If the first argument is !, the value is the negation of
the two-argument test using the second and third arguments.
If the first argument is exactly ( and the third argument is
exactly ), the result is the one-argument test of the second
argument.
Otherwise, the expression is false.
- 4 arguments
-
If the first argument is !, the result is the negation of
the three-argument expression composed of the remaining arguments.
Otherwise, the expression is parsed and evaluated according to
precedence using the rules listed above.
- 5 or more arguments
-
The expression is parsed and evaluated according to precedence
using the rules listed above.
- times
-
Print the accumulated user and system times for the shell and
for processes run from the shell. The return status is 0.
- trap [-lp] [[arg] sigspec ...]
-
The command
arg
is to be read and executed when the shell receives
signal(s)
sigspec.
If
arg
is absent (and there is a single sigspec) or
-,
each specified signal is
reset to its original disposition (the value it had
upon entrance to the shell).
If
arg
is the null string the signal specified by each
sigspec
is ignored by the shell and by the commands it invokes.
If
arg
is not present and
-p
has been supplied, then the trap commands associated with each
sigspec
are displayed.
If no arguments are supplied or if only
-p
is given,
trap
prints the list of commands associated with each signal.
The
-l
option causes the shell to print a list of signal names and
their corresponding numbers.
Each
sigspec
is either
a signal name defined in <signal.h>, or a signal number.
Signal names are case insensitive and the SIG prefix is optional.
If a
sigspec
is
EXIT
(0) the command
arg
is executed on exit from the shell.
If a
sigspec
is
DEBUG,
the command
arg
is executed before every simple command, for command,
case command, select command, every arithmetic for
command, and before the first command executes in a shell function (see
SHELL GRAMMAR
above).
Refer to the description of the extdebug option to the
shopt builtin for details of its effect on the DEBUG trap.
If a
sigspec
is
RETURN,
the command
arg
is executed each time a shell function or a script executed with the
. or source builtins finishes executing.
If a
sigspec
is
ERR,
the command
arg
is executed whenever a simple command has a non-zero exit status,
subject to the following conditions.
The
ERR
trap is not executed if the failed
command is part of the command list immediately following a
while
or
until
keyword,
part of the test in an
if
statement, part of a command executed in a
&&
or
||
list, or if the command's return value is
being inverted via
!.
These are the same conditions obeyed by the errexit option.
Signals ignored upon entry to the shell cannot be trapped or reset.
Trapped signals that are not being ignored are reset to their original
values in a subshell or subshell environment when one is created.
The return status is false if any
sigspec
is invalid; otherwise
trap
returns true.
- type [-aftpP] name [name ...]
-
With no options,
indicate how each
name
would be interpreted if used as a command name.
If the
-t
option is used,
type
prints a string which is one of
alias,
keyword,
function,
builtin,
or
file
if
name
is an alias, shell reserved word, function, builtin, or disk file,
respectively.
If the
name
is not found, then nothing is printed, and an exit status of false
is returned.
If the
-p
option is used,
type
either returns the name of the disk file
that would be executed if
name
were specified as a command name,
or nothing if
``type -t name''
would not return
file.
The
-P
option forces a
PATH
search for each name, even if
``type -t name''
would not return
file.
If a command is hashed,
-p
and
-P
print the hashed value, not necessarily the file that appears
first in
PATH.
If the
-a
option is used,
type
prints all of the places that contain
an executable named
name.
This includes aliases and functions,
if and only if the
-p
option is not also used.
The table of hashed commands is not consulted
when using
-a.
The
-f
option suppresses shell function lookup, as with the command builtin.
type
returns true if all of the arguments are found, false if
any are not found.
- ulimit [-HSTabcdefilmnpqrstuvx [limit]]
-
Provides control over the resources available to the shell and to
processes started by it, on systems that allow such control.
The -H and -S options specify that the hard or soft limit is
set for the given resource.
A hard limit cannot be increased by a non-root user once it is set;
a soft limit may be increased up to the value of the hard limit.
If neither -H nor -S is specified, both the soft and hard
limits are set.
The value of
limit
can be a number in the unit specified for the resource
or one of the special values
hard,
soft,
or
unlimited,
which stand for the current hard limit, the current soft limit, and
no limit, respectively.
If
limit
is omitted, the current value of the soft limit of the resource is
printed, unless the -H option is given. When more than one
resource is specified, the limit name and unit are printed before the value.
Other options are interpreted as follows:
-
- -a
-
All current limits are reported
- -b
-
The maximum socket buffer size
- -c
-
The maximum size of core files created
- -d
-
The maximum size of a process's data segment
- -e
-
The maximum scheduling priority ("nice")
- -f
-
The maximum size of files written by the shell and its children
- -i
-
The maximum number of pending signals
- -l
-
The maximum size that may be locked into memory
- -m
-
The maximum resident set size (many systems do not honor this limit)
- -n
-
The maximum number of open file descriptors (most systems do not
allow this value to be set)
- -p
-
The pipe size in 512-byte blocks (this may not be set)
- -q
-
The maximum number of bytes in POSIX message queues
- -r
-
The maximum real-time scheduling priority
- -s
-
The maximum stack size
- -t
-
The maximum amount of cpu time in seconds
- -u
-
The maximum number of processes available to a single user
- -v
-
The maximum amount of virtual memory available to the shell
- -x
-
The maximum number of file locks
- -T
-
The maximum number of threads
If
limit
is given, it is the new value of the specified resource (the
-a
option is display only).
If no option is given, then
-f
is assumed. Values are in 1024-byte increments, except for
-t,
which is in seconds,
-p,
which is in units of 512-byte blocks,
and
-T,
-b,
-n,
and
-u,
which are unscaled values.
The return status is 0 unless an invalid option or argument is supplied,
or an error occurs while setting a new limit.
- umask [-p] [-S] [mode]
-
The user file-creation mask is set to
mode.
If
mode
begins with a digit, it
is interpreted as an octal number; otherwise
it is interpreted as a symbolic mode mask similar
to that accepted by
chmod(1).
If
mode
is omitted, the current value of the mask is printed.
The
-S
option causes the mask to be printed in symbolic form; the
default output is an octal number.
If the
-p
option is supplied, and
mode
is omitted, the output is in a form that may be reused as input.
The return status is 0 if the mode was successfully changed or if
no mode argument was supplied, and false otherwise.
- unalias [-a] [name ...]
-
Remove each name from the list of defined aliases. If
-a
is supplied, all alias definitions are removed. The return
value is true unless a supplied
name
is not a defined alias.
- unset [-fv] [name ...]
-
For each
name,
remove the corresponding variable or function.
If no options are supplied, or the
-v
option is given, each
name
refers to a shell variable.
Read-only variables may not be unset.
If
-f
is specified, each
name
refers to a shell function, and the function definition
is removed.
Each unset variable or function is removed from the environment
passed to subsequent commands.
If any of
COMP_WORDBREAKS,
RANDOM,
SECONDS,
LINENO,
HISTCMD,
FUNCNAME,
GROUPS,
or
DIRSTACK
are unset, they lose their special properties, even if they are
subsequently reset. The exit status is true unless a
name
is readonly.
- wait [n ...]
-
Wait for each specified process and return its termination status.
Each
n
may be a process
ID or a job specification; if a job spec is given, all processes
in that job's pipeline are waited for. If
n
is not given, all currently active child processes
are waited for, and the return status is zero. If
n
specifies a non-existent process or job, the return status is
127. Otherwise, the return status is the exit status of the last
process or job waited for.