Go to the first, previous,next, last section, table of contents.


 .   :   [   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 

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 ;fi

Any  trap 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

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, 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.

  1. 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.

variables used:
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.
! expr
True if expr is false.
( expr )
Returns the value of expr. 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.
These builtins evaluate conditional expressions using a set of rules based on the number of arguments.
0 arguments
The expression is false.
1 argument ex: [ $VAR
The expression is true if and only if the argument is not null.
2 arguments
ex: [ ! $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.
3 arguments ex: [ $SUM -gt 0
If the second argument is one of the binary conditional operators (see section Bash Conditional Expressions), the result of the expression is the result of the binary test using the first and third arguments as operands.
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.
4 arguments ex: [ ! $SUM -gt 0 required space after !
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 ex: [
The expression is parsed and evaluated according to precedence using the rules listed above.

times

Output to stdout the user and system times used by the shell and its children since being invoked.

ex:
0m0.060s 0m0.260s
0m1.250s 0m2.240s

The return status is 0.

To time a command see the utility: time

trap [-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 prints the list of commands associated with each signal number in a form that may be reused as shell input.
trap -l lists signal names and their corresponding numbers.

example from BSD:
 
Name      Default Action          
EXIT    0
HUP     1 terminate process terminal line HangUP
INT     2 terminate process INTerrupt program
QUIT    3 create core image QUIT program

ILL     4 create core image ILLegal instruction
TRAP    5 create core image trace TRAP
ABRT    6 create core image ABoRT program (formerly IOT)

EMT     7 create core image EMulaTe instruction executed
FPE     8 create core image Floating-Point Exception
KILL    9 terminate process KILL program

BUS    10 create core image BUS error
SEGV   11 create core image SEGmentation Violation
SYS    12 create core image non-existent SYStem call invoked

PIPE   13 terminate process write on a PIPE with no reader
ALRM   14 terminate process real-time timer expired (alarm)
TERM   15 terminate process software TERMination signal

Name      Default Action
URG    16 discard signal    URGent condition present on socket
STOP   17 stop process      STOP (cannot be caught or ignored)
TSTP   18 stop process      Terminal generated SToP signal (i.e. from keyboard)

CONT   19 discard signal    CONTinue after stop
CHLD   20 discard signal    CHiLD status has changed
TTIN   21 stop process      TTY background INput attempted from control terminal 
TTOU   22 stop process      TTY background OUtput attempted to control terminal

IO     23 discard signal    I/O is possible on a descriptor (see fcntl(2))

XCPU   24 terminate process eXceeded CPU time limit (see setrlimit(2))
XFSZ   25 terminate process eXceeded File SiZe limit (see setrlimit(2))
VTALRM 26 terminate process Virtual Time Alarm (see setitimer(2))
PROF   27 terminate process PROFiling timer alarm (see setitimer(2))

WINCH  28 discard signal    WINdow size CHange
INFO   29 discard signal    status request from keyboard
USR1   30 terminate process User defined signal 1
USR2   31 terminate process User defined signal 2
Signals ignored upon entry to the shell cannot be trapped or reset.
Signals issued by kill -sigspec PID may remain in pending state if the script is processing a wait until the wait time expires. See
bash signals.
A KILL issued to a process in a wait will cause the wait to expire immediately.
Trapped signals are reset to their original values in a child process when it is created.
The return status is 0 or, 1 if sigspec does not specify a valid signal.

Example:
trap "echo \"+exiting+\"; rm -f /tmp/${TMP}*; exit 1" EXIT
trap -p
   trap -- 'echo "+exiting+"; rm -f /tmp/*; exit 1' EXIT


Variables

CDPATH colon-separated list of directories used as a search path for cd.
HOME current user's home directory; the default for the cd builtin command. The value of this variable is also used by tilde expansion (see section Tilde Expansion).
IFS Input Field SeperatorsA list of characters that separate fields; used when the shell splits words as part of expansion.
MAIL If this parameter is set to a filename and the MAILPATH variable is not set, Bash informs the user of the arrival of mail in the specified file.
MAILPATH     A colon-separated list of filenames which the shell periodically checks for new mail. Each list entry can specify the message that is printed when new mail arrives in the mail file by separating the file name from the message with a ?. When used in the text of the message, $_ expands to the name of the current mail file.
OPTARG The value of the last option argument processed by the getopts builtin.
OPTIND The index of the last option argument processed by the getopts builtin.
PATH A colon-separated list of directories in which the shell looks for commands.
PS1 The primary prompt string, default \s-\v\$ (i.e.qqqqqq ) .
PS2 The secondary prompt string, default > .
next, last section, table of contents.