-a allexport |
| Flag variables for export when assignments are made to them. |
-b notify |
| Enable asynchronous notification of background job completion. (UNIMPLEMENTED) |
-C noclobber |
| Do not overwrite existing files with ">". |
-E emacs |
| Enable the built-in emacs(1) command line editor (disables the -V option if it has been set). |
-e errexit |
| Exit immediately if any untested command fails in non-interactive mode. The exit status of a command is considered to be explicitly tested if the command is used to control an if, elif, while, or until; or if the command is the left hand operand of an "&&" or "||" operator. |
-f noglob |
| Disable pathname expansion. |
-I ignoreeof |
| Ignore EOF s from input when in interactive mode. |
-i interactive |
| Force the shell to behave interactively. |
-m monitor |
| Turn on job control (set automatically when interactive). |
-n noexec |
| If not interactive, read commands but do not execute them. This is useful for checking the syntax of shell scripts. |
-P physical |
| Change the default for the cd and pwd commands from -L (logical directory layout) to -P (physical directory layout). |
-p privileged |
| Turn on privileged mode. This mode is enabled on startup if either the effective user or group id is not equal to the real user or group id. Turning this mode off sets the effective user and group ids to the real user and group ids. When this mode is enabled for interactive shells, the file /etc/suid_profile is sourced instead of ~/.profile after /etc/profile is sourced, and the contents of the ENV variable are ignored. |
-s stdin |
| Read commands from standard input (set automatically if no file arguments are present). This option has no effect when set after the shell has already started running (i.e., when set with the set command). |
-T trapsasync |
| When waiting for a child, execute traps immediately. If this option is not set, traps are executed after the child exits, as specified in -p1003.2. This nonstandard option is useful for putting guarding shells around children that block signals. The surrounding shell may kill the child or it may just return control to the tty and leave the child alone, like this:
sh -T -c "trap exit 1 2 ; some-blocking-program"
|
-u nounset |
| Write a message to standard error when attempting to expand a variable that is not set, and if the shell is not interactive, exit immediately. |
-V vi | Enable the built-in vi(1) command line editor (disables -E if it has been set). |
-v verbose |
| The shell writes its input to standard error as it is read. Useful for debugging. |
-x xtrace |
| Write each command (preceded by ""+ "") to standard error before it is executed. Useful for debugging. |
|
[n]> file | redirect stdout (or file descriptor n) to file |
[n]>| file | same as above, but override the -C option |
[n]>> file |
| append stdout (or file descriptor n) to file |
[n]< file | redirect stdin (or file descriptor n) from file |
[n]<> file |
| redirect stdin (or file descriptor n) to and from file |
[n1]<&n2 | duplicate stdin (or file descriptor n1) from file descriptor n2 |
[n]<&- | close stdin (or file descriptor n) |
[n1]>&n2 | duplicate stdout (or file descriptor n1) to file descriptor n2 |
[n]>&- | close stdout (or file descriptor n) |
|
The following redirection is often called a "here-document".
[n]<< delimiter
here-doc-text
...
delimiter
$* | Expands to the positional parameters, starting from one. When the expansion occurs within a double-quoted string it expands to a single field with the value of each parameter separated by the first character of the IFS variable, or by a <space> if IFS is unset. |
$@ | Expands to the positional parameters, starting from one. When the expansion occurs within double-quotes, each positional parameter expands as a separate argument. If there are no positional parameters, the expansion of @ generates zero arguments, even when @ is double-quoted. What this basically means, for example, is if $1 is "abc" and $2 is "def ghi", then "$@" expands to the two arguments:
"abc" "def ghi"
|
$# | Expands to the number of positional parameters. |
$? | Expands to the exit status of the most recent pipeline. |
$- | (hyphen) Expands to the current option flags (the single-letter option names concatenated into a string) as specified on invocation, by the set built-in command, or implicitly by the shell. |
$$ | Expands to the process ID of the invoked shell. A subshell retains the same value of $ as its parent. |
$! | Expands to the process ID of the most recent background command executed from the current shell. For a pipeline, the process ID is that of the last command in the pipeline. |
$0 | (zero) Expands to the name of the shell or shell script. |
|
Word Expansions
This clause describes the various expansions that are performed on words. Not all expansions are performed on every word, as explained later. Tilde expansions, parameter expansions, command substitutions, arithmetic expansions, and quote removals that occur within a single word expand to a single field. It is only field splitting or pathname expansion that can create multiple fields from a single word. The single exception to this rule is the expansion of the special parameter @ within double-quotes, as was described above.
The order of word expansion is:
- Tilde Expansion, Parameter Expansion, Command Substitution, Arithmetic Expansion (these all occur at the same time).
- Field Splitting is performed on fields generated by step (1) unless the IFS variable is null.
- Pathname Expansion (unless the -f option is in effect).
- Quote Removal.
The "$" character is used to introduce parameter expansion, command substitution, or arithmetic evaluation.
Tilde Expansion (substituting a users home directory)
A word beginning with an unquoted tilde character (~) is subjected to tilde expansion. All the characters up to a slash (/) or the end of the word are treated as a username and are replaced with the users home directory. If the username is missing (as in ~/foobar), the tilde is replaced with the value of the HOME variable (the current users home directory).
Parameter Expansion
The format for parameter expansion is as follows:
${expression}
where expression consists of all characters until the matching "}". Any "}" escaped by a backslash or within a quoted string, and characters in embedded arithmetic expansions, command substitutions, and variable expansions, are not examined in determining the matching "}".
The simplest form for parameter expansion is:
${parameter}
The value, if any, of parameter is substituted.
The parameter name or symbol can be enclosed in braces, which are optional except for positional parameters with more than one digit or when parameter is followed by a character that could be interpreted as part of the name. If a parameter expansion occurs inside double-quotes:
- Pathname expansion is not performed on the results of the expansion.
- Field splitting is not performed on the results of the expansion, with the exception of the special parameter @.
In addition, a parameter expansion can be modified by using one of the following formats.
${parameter:-word} |
| Use Default Values. If parameter is unset or null, the expansion of word is substituted; otherwise, the value of parameter is substituted. |
${parameter:=word} |
| Assign Default Values. If parameter is unset or null, the expansion of word is assigned to parameter. In all cases, the final value of parameter is substituted. Only variables, not positional parameters or special parameters, can be assigned in this way. |
${parameter:?[word]} |
| Indicate Error if Null or Unset. If parameter is unset or null, the expansion of word (or a message indicating it is unset if word is omitted) is written to standard error and the shell exits with a nonzero exit status. Otherwise, the value of parameter is substituted. An interactive shell need not exit. |
${parameter:+word} |
| Use Alternate Value. If parameter is unset or null, null is substituted; otherwise, the expansion of word is substituted. |
|
In the parameter expansions shown previously, use of the colon in the format results in a test for a parameter that is unset or null; omission of the colon results in a test for a parameter that is only unset.
The following four varieties of parameter expansion provide for substring processing. In each case, pattern matching notation (see Shell Patterns), rather than regular expression notation, is used to evaluate the patterns. If parameter is one of the special parameters * or @, the result of the expansion is unspecified. Enclosing the full parameter expansion string in double-quotes does not cause the following four varieties of pattern characters to be quoted, whereas quoting characters within the braces has this effect.
: | A null command that returns a 0 (true) exit value. |
. file | The commands in the specified file are read and executed by the shell. The return command may be used to return to the . commands caller. If file contains any "/" characters, it is used as is. Otherwise, the shell searches the PATH for the file. If it is not found in the PATH, it is sought in the current working directory. |
alias [name ...] alias [name = string ...] |
| If name = string is specified, the shell defines the alias name with value string. If just name is specified, the value of the alias name is printed. With no arguments, the alias built-in command prints the names and values of all defined aliases (see unalias). Alias values are written with appropriate quoting so that they are suitable for re-input to the shell. |
bg [job ...] |
| Continue the specified jobs (or the current job if no jobs are given) in the background. |
builtin cmd [arg ...] |
| Execute the specified built-in command, cmd. This is useful when the user wishes to override a shell function with the same name as a built-in command. |
bind[-aeklrsv[key[command]]] |
| List or alter key bindings for the line editor. This command is documented in editrc(5). |
cd[-L-| -P [directory]] |
| Switch to the specified directory, or to the directory specified in the HOME environment variable if no directory is specified. If directory does not begin with /, ., or .., then the directories listed in the CDPATH variable will be searched for the specified directory. If CDPATH is unset, the current directory is searched. The format of CDPATH is the same as that of PATH. In an interactive shell, the cd command will print out the name of the directory that it actually switched to if this is different from the name that the user gave. These may be different either because the CDPATH mechanism was used or because a symbolic link was crossed. If the -P option is specified, .. is handled physically and symbolic links are resolved before .. components are processed. If the -L option is specified, .. is handled logically. This is the default. |
chdir | A synonym for the cd built-in command. |
command[-p[utility [argument ...]]] |
| Execute the specified utility as a simple command (see the Simple Commands section). If the -p option is specified, the command search is performed using a default value of PATH that is guaranteed to find all of the standard utilities. |
echo[-e-| -n [string]] |
| Print string to the standard output with a newline appended. |
-n | Suppress the output of the trailing newline. |
-e | Process C-style backslash escape sequences. echo understands the following character escapes: |
\a | Alert (ring the terminal bell) |
\b | Backspace |
\c | Suppress the trailing newline (this has the side-effect of truncating the line if it is not the last character) |
\e | The ESC character (ASCII 0x1b) |
\f | Formfeed |
\n | Newline |
\r | Carriage return |
\t | Horizontal tab |
\v | Vertical tab |
\\ | Literal backslash |
\0nnn | (Zero) The character whose octal value is nnn |
|
eval string ... |
| Concatenate all the arguments with spaces. Then re-parse and execute the command. |
exec [command [arg ...]] |
| Unless command is omitted, the shell process is replaced with the specified program (which must be a real program, not a shell built-in command or function). Any redirections on the exec command are marked as permanent, so that they are not undone when the exec command finishes. |
exit [exitstatus] |
| Terminate the shell process. If exitstatus is given it is used as the exit status of the shell; otherwise the exit status of the preceding command is used. |
export[-p[name ...]] |
| The specified names are exported so that they will appear in the environment of subsequent commands. The only way to un-export a variable is to unset it. The shell allows the value of a variable to be set at the same time as it is exported by writing
export name=value
With no arguments the export command lists the names of all exported variables. If the -p option is specified, the exported variables are printed as "export name = value" lines, suitable for re-input to the shell. |
fc[-e editor[first [last]]] fc-l [-nr[first [last]]] fc-s [old = new[first]] |
| The fc built-in command lists, or edits and re-executes, commands previously entered to an interactive shell. |
-e editor |
| Use the editor named by editor to edit the commands. The editor string is a command name, subject to search via the PATH variable. The value in the FCEDIT variable is used as a default when -e is not specified. If FCEDIT is null or unset, the value of the EDITOR variable is used. If EDITOR is null or unset, ed(1) is used as the editor. |
-l (ell) |
| List the commands rather than invoking an editor on them. The commands are written in the sequence indicated by the first and last operands, as affected by -r , with each command preceded by the command number. |
-n | Suppress command numbers when listing with -l . |
-r | Reverse the order of the commands listed (with -l ) or edited (with neither -l nor -s ). |
-s | Re-execute the command without invoking an editor. |
first last |
| Select the commands to list or edit. The number of previous commands that can be accessed are determined by the value of the HISTSIZE variable. The value of first or last or both are one of the following: |
[+]num |
| A positive number representing a command number; command numbers can be displayed with the -l option. |
-num | A negative decimal number representing the command that was executed num of commands previously. For example, -1 is the immediately previous command. |
string |
| A string indicating the most recently entered command that begins with that string. If the old=new operand is not also specified with -s , the string form of the first operand cannot contain an embedded equal sign. |
|
fg [job] | Move the specified job or the current job to the foreground. |
getopts optstring var |
| The POSIX getopts command. The getopts command deprecates the older getopt(1) command. The first argument should be a series of letters, each possibly followed by a colon which indicates that the option takes an argument. The specified variable is set to the parsed option. The index of the next argument is placed into the shell variable OPTIND. If an option takes an argument, it is placed into the shell variable OPTARG. If an invalid option is encountered, var is set to "?". It returns a false value (1) when it encounters the end of the options. |
hash[-rv[command ...]] |
| The shell maintains a hash table which remembers the locations of commands. With no arguments whatsoever, the hash command prints out the contents of this table. Entries which have not been looked at since the last cd command are marked with an asterisk; it is possible for these entries to be invalid. With arguments, the hash command removes each specified command from the hash table (unless they are functions) and then locates it. With the -v option, hash prints the locations of the commands as it finds them. The -r option causes the hash command to delete all the entries in the hash table except for functions. |
jobid [job] | Print the process ids of the processes in the specified job. If the job argument is omitted, use the current job. |
jobs[-ls[job ...]] |
| Print information about the specified jobs, or all jobs if no job argument is given. The information printed includes job ID, status and command name. If the -l option is specified, the PID of each job is also printed. If the -s option is specified, only the PIDs of the jobs are printed, one per line. |
pwd [-L-| -P ] |
| Print the path of the current directory. The built-in command may differ from the program of the same name because the built-in command remembers what the current directory is rather than recomputing it each time. This makes it faster. However, if the current directory is renamed, the built-in version of pwd(1) will continue to print the old name for the directory. If the -P option is specified, symbolic links are resolved. If the -L option is specified, the shells notion of the current directory is printed (symbolic links are not resolved). This is the default. |
read[-p prompt[-ttimeout[-ervariable...]]] |
| The prompt is printed if the -p option is specified and the standard input is a terminal. Then a line is read from the standard input. The trailing newline is deleted from the line and the line is split as described in the section on White Space Splitting (Field Splitting) above, and the pieces are assigned to the variables in order. If there are more pieces than variables, the remaining pieces (along with the characters in IFS that separated them) are assigned to the last variable. If there are more variables than pieces, the remaining variables are assigned the null string. Backslashes are treated specially, unless the -r option is specified. If a backslash is followed by a newline, the backslash and the newline will be deleted. If a backslash is followed by any other character, the backslash will be deleted and the following character will be treated as though it were not in IFS, even if it is. If the -t option is specified and the timeout elapses before any input is supplied, the read command will return without assigning any values. The timeout value may optionally be followed by one of "s", "m" or "h" to explicitly specify seconds, minutes or hours. If none is supplied, "s" is assumed. The -e option exists only for backward compatibility with older scripts. |
readonly[-p[name ...]] |
| Each specified name is marked as read only, so that it cannot be subsequently modified or unset. The shell allows the value of a variable to be set at the same time as it is marked read only by using the following form:
readonly name=value
With no arguments the readonly command lists the names of all read only variables. If the -p option is specified, the read-only variables are printed as "readonly name = value" lines, suitable for re-input to the shell. |
set[-/+abCEefIimnpTuVvx[-/+olongname[]] |
| -c string[-- arg ...]] The set command performs three different functions: |
|
setvar variable value | Assigns the specified value to the specified variable. Setvar is intended to be used in functions that assign values to variables whose names are passed as parameters. In general it is better to write
variable=value
rather than using setvar. |
shift [n] | Shift the positional parameters n times, or once if n is not specified. A shift sets the value of $1 to the value of $2, the value of $2 to the value of $3, and so on, decreasing the value of $# by one. If there are zero positional parameters, shifting does not do anything. |
trap[actionsignal ...] | Cause the shell to parse and execute action when any specified signal is received. The signals are specified by name or number. In addition, the pseudo-signal EXIT may be used to specify an action that is performed when the shell terminates. The action may be null or omitted; the former causes the specified signal to be ignored and the latter causes the default action to be taken. When the shell forks off a subshell, it resets trapped (but not ignored) signals to the default action. The trap command has no effect on signals that were ignored on entry to the shell. |
type [name ...] | Interpret each name as a command and print the resolution of the command search. Possible resolutions are: shell keyword, alias, shell built-in command, command, tracked alias and not found. For aliases the alias expansion is printed; for commands and tracked aliases the complete pathname of the command is printed. |
ulimit[-HSabcdflmnstuv[limit]] | Set or display resource limits (see getrlimit(2)). If limit is specified, the named resource will be set; otherwise the current resource value will be displayed. If -H is specified, the hard limits will be set or displayed. While everybody is allowed to reduce a hard limit, only the superuser can increase it. The -S option specifies the soft limits instead. When displaying limits, only one of -S or -H can be given. The default is to display the soft limits, and to set both the hard and the soft limits. Option -a causes the ulimit command to display all resources. The parameter limit is not acceptable in this mode. The remaining options specify which resource value is to be displayed or modified. They are mutually exclusive. |
-b sbsize |
| The maximum size of socket buffer usage, in bytes. |
-c coredumpsize |
| The maximal size of core dump files, in 512-byte blocks. |
-d datasize |
| The maximal size of the data segment of a process, in kilobytes. |
-f filesize |
| The maximal size of a file, in 512-byte blocks. |
-l lockedmem |
| The maximal size of memory that can be locked by a process, in kilobytes. |
-m memoryuse |
| The maximal resident set size of a process, in kilobytes. |
-n nofiles |
| The maximal number of descriptors that could be opened by a process. |
-s stacksize |
| The maximal size of the stack segment, in kilobytes. |
-t time |
| The maximal amount of CPU time to be used by each process, in seconds. |
-u userproc |
| The maximal number of simultaneous processes for this user ID. |
-v virtualmem |
| The maximal virtual size of a process, in kilobytes. |
|
umask [mask] |
| Set the file creation mask (see umask(2)) to the octal value specified by mask. If the argument is omitted, the current mask value is printed. |
unalias[-a[name]] |
| If name is specified, the shell removes that alias. If -a is specified, all aliases are removed. |
unset[-fvname ...] |
| The specified variables or functions are unset and unexported. If the -v option is specified or no options are given, the name arguments are treated as variable names. If the -f option is specified, the name arguments are treated as function names. |
wait [job] |
| Wait for the specified job to complete and return the exit status of the last process in the job. If the argument is omitted, wait for all jobs to complete and return an exit status of zero. |
|
CDPATH | The search path used with the cd built-in. |
EDITOR | The fallback editor used with the fc built-in. If not set, the default editor is ed(1). |
FCEDIT | The default editor used with the fc built-in. |
HISTSIZE | The number of previous commands that are accessible. |
HOME | The starting directory of sh. |
IFS | Input Field Separators. This is normally set to <space>, <tab>, and <newline>. See the White Space Splitting section for more details. |
MAIL | The name of a mail file, that will be checked for the arrival of new mail. Overridden by MAILPATH. |
MAILPATH | A colon (:) separated list of file names, for the shell to check for incoming mail. This environment setting overrides the MAIL setting. There is a maximum of 10 mailboxes that can be monitored at once. |
PATH | The default search path for executables. See the Path Search section for details. |
PS1 | The primary prompt string, which defaults to ""$ "", unless you are the superuser, in which case it defaults to ""# "". |
PS2 | The secondary prompt string, which defaults to ""> "". |
TERM | The default terminal setting for the shell. This is inherited by children of the shell, and is used in the history editing modes. |
|