.
:
[
alias
bg
bind
break
builtin
cd
command
continue
declare
dirs
disown
echo
enable
eval
exec
exit
export
fc
fg
getopts
hash
help
history
jobs
kill
let
local
logout
popd
printf
pushd
pwd
read
readonly
return
set
shift
shopt
source
suspend
test
times
trap
type
typeset
ulimit
umask
unalias
unset
wait
Any
optstring contains the option letters to be recognized; if a letter is followed by a colon, the option is expected to have an argument, which should be separated from it by white space. Each time it is invoked,
variables used:
ex:
The return status is 0.
To time a command see the utility: time
eval [arguments]
The arguments are concatenated together into a single command, which is
then read and executed, and its exit status returned as the exit status of
eval.
If there are no arguments or only empty arguments, the return status is 0.
cd [-LP] [directory]
Change the current working directory to directory.
Default is HOME.
If CDPATH exists, it is used as a search path.
i.e. home > cd docs changes current working directory to home/docs.
If directory begins with a slash, CDPATH is not used.
i.e. home > cd /docs changes current working directory to /docs.
-L follow symbolic links, default
-P Prevent symbolic links from being followed.
If directory is -, $OLDPWD (i.e. previous ) is used.
The return status is 0 if the directory is successfully changed, non-zero otherwise. i.e. 1
exec [-cl] [-a name] [command [arguments]]
If command is supplied, it replaces the shell without
creating a new process.
-c causes command to be executed with an empty environment.
-l the shell passes - as the zeroth arg passed to command. This is what the login program does.
-a the shell passes name as the zeroth
argument to command.
If no command is specified,
redirections may be used to affect the current shell environment.
If there are no redirection errors, the return status is 0; otherwise non-zero.
exit [n]
Exit the shell, returning a status of n to the shell's
parent who can examine it as $? Ex:.
RC=$?; if [ $RC -ne 0 ]; then echo " " ++++ RC= $RC ;fitrap on EXIT is executed before the shell terminates.
export [-fn] [-p] [name[=value]]
Mark each name to be passed to child processes in the environment.
-f the names refer to shell functions; otherwise the names refer to shell variables.
-n no longer mark each name for
export. If no names are supplied, or if the -p
option is given, a list of exported names is displayed.
-p display output in a form that may be reused as input.
The return status is 0 unless an invalid option is supplied, one of the names is not a
valid shell variable name, or -f is supplied with a name that
is not a shell function.
getopts optstring name [args]
parses positional parameters.
Ex: getopts qqqqqqabvV options 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 0.
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 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.
OPTERR if 0 supress error display.
name
OPTIND set to index of first non-otion arg
OPTARG set to arg of
name set to ?
optstring>
hash [-r] [-p filename] [name]
Remember the full pathnames of commands specified as name
arguments, so they need not be searched for on subsequent invocations. The
commands are found by searching through the directories listed in
$PATH.
-p inhibits the path search, and
filename is used as the location of name.
-r forget all remembered locations.
If no arguments are given, information about remembered commands is printed.
The return status is 0 unless a name is not found or an invalid
option is supplied.
readonly [-apf] [name] ...
Mark each name as readonly. The values of these names may not
be changed by subsequent assignment.
-f each name refers to a shell function.
-a each name refers to an array variable.
If no name arguments are given, or if the
-p option is supplied, a list of all readonly names is printed.
-p display in a format that may be reused as input.
The return status is 0 unless an invalid option is
supplied, one of the name arguments is not a valid shell variable
or function name, or the -f option is supplied with a name that
is not a shell function.
return [n]
Cause a shell function to exit with the return value n. This
may also be used to terminate execution of a script being executed with the
. builtin, returning either n or the exit status of
the last command executed within the script as the exit status of the script.
The return status is false if return is used outside a function
and not during the execution of a script by ..
shift [n]
Shift the positional parameters to the left by n. The
positional parameters from n+1 ... $# are renamed to
$1 ... $#-n+1. Parameters represented by
the numbers $# to n+1 are unset. n must be
a non-negative number less than or equal to $#.
If n is 0 or greater than $#, the positional parameters are not
changed.
The return status is 0 unless n is greater than
$# or less than 0, non-zero otherwise.
test expr [ expr
Evaluate a conditional expression
expr. Each operator and operand must be a separate argument.
Expressions are composed of the primaries described in section
Bash Conditional Expressions.
Expressions may be combined using the following operators, listed in decreasing order of precedence.
These
builtins evaluate conditional expressions
using a set of rules based on the number of arguments.
! expr
( expr )
expr1 -a expr2
expr1 -o expr2
[ $VAR [ ! $COUNTER
If the first argument is !, the expression is true if and only if the second argument is null.
ex: [ -f /loginhush
If the first argument is one of the unary conditional operators (see section
Bash Conditional Expressions), the expression is true if the unary test is true.
If the first argument is not a valid unary operator, the expression is false.
[ $SUM -gt 0
If the first argument is !, the value is the negation of the two-argument test using the second and third arguments.
ex: [ ( $VAR )
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.
The -a and -o operators are considered binary operators in this case.
[ ! $SUM -gt 0 required space after !
[
times †
Output to stdout the user and system times used by the shell and its children since being invoked.
0m0.060s 0m0.260s
0m1.250s 0m2.240strap [-lp] [commands] [sigspec ...]
commands are executed when the shell receives signal sigspec.
Each sigspec is a signal name such as INT (optional SIG prefix) or a signal number.
trap sigspec | sigspec is ignored by the shell and commands it invokes. | |||||||||||||
trap 0 or EXIT | commands are executed when the shell exits. | |||||||||||||
trap DEBUG | commands are executed BEFORE! simple commands. | |||||||||||||
trap - | specified signals are reset to the values they had when the shell was started. | |||||||||||||
trap -p | prints commands associated with each sigspec. | |||||||||||||
trap | ||||||||||||||
kill -sigspec PID may remain in pending state if
the script is processing a wait until the wait time expires.
See bash signals.KILL issued to a process in a wait will cause the wait to expire immediately.
Example:
trap "echo \"+exiting+\"; rm -f /tmp/${TMP}*; exit 1" EXIT
trap -p
trap -- 'echo "+exiting+"; rm -f /tmp/*; exit 1' EXIT
Variables
next, last
section, table of contents.