bash(1) - GNU Bourne-Again SHell

-c

If the -c option is present, then commands are read from the first non-option argument command_string. If there are arguments after the command_string, the first argument is assigned to $0 and any remaining arguments are assigned to the positional parameters. The assignment to $0 sets the name of the shell, which is used in warning and error messages.

-i

If the -i option is present, the shell is interactive.

-l

Make bash act as if it had been invoked as a login shell (see INVOCATION below).

-D

Print a list of all double-quoted strings preceded by $ on the standard output. These are the strings that are subject to language translation when the current locale is not C or POSIX. This implies the -n option; no commands will be executed.

[-+]O [shopt_option]

shopt_option is one of the shell options accepted by the shopt builtin (see SHELL BUILTIN COMMANDS below). If shopt_option is present, -O sets the value of that option; +O unsets it. If shopt_option is not supplied, bash prints the names and values of the shell options accepted by shopt on the standard output. If the invocation option is +O, the output is displayed in a format that may be reused as input.

--

A -- signals the end of options and disables further option processing. Any arguments after the -- are treated as a shell script filename (see below) and arguments passed to that script. An argument of - is equivalent to --.

--debugger

Arrange for the debugger profile to be executed before the shell starts. Turns on extended debugging mode (see the description of the extdebug option to the shopt builtin below).

--dump-po-strings

Equivalent to -D, but the output is in the GNU gettext “po” (portable object) file format.

--dump-strings

Equivalent to -D.

--help

Display a usage message on standard output and exit successfully.

--init-file file

--rcfile file

Execute commands from file instead of the system wide initialization file /etc/bash.bashrc and the standard personal initialization file ~/.bashrc if the shell is interactive (see INVOCATION below).

--login

Equivalent to -l.

--noediting

Do not use the GNU readline library to read command lines when the shell is interactive.

--noprofile

Do not read either the system-wide startup file /etc/profile or any of the personal initialization files ~/.bash_profile, ~/.bash_login, or ~/.profile. By default, bash reads these files when it is invoked as a login shell (see INVOCATION below).

--norc

Do not read and execute the system wide initialization file /etc/bash.bashrc and the personal initialization file ~/.bashrc if the shell is interactive. This option is on by default if the shell is invoked as sh.

--posix

Enable posix mode; change the behavior of bash where the default operation differs from the POSIX standard to match the standard.

--restricted

The shell becomes restricted (see RESTRICTED SHELL below).

--verbose

Equivalent to -v.

--version

Show version information for this instance of bash on the standard output and exit successfully.

declare -a name

(see SHELL BUILTIN COMMANDS below).

declare -a name[subscript]

is also accepted; the subscript is ignored.

-A action

The action may be one of the following to generate a list of possible completions:

alias

Alias names. May also be specified as -a.

arrayvar

Array variable names.

binding

Readline key binding names.

builtin

Names of shell builtin commands. May also be specified as -b.

command

Command names. May also be specified as -c.

directory

Directory names. May also be specified as -d.

disabled

Names of disabled shell builtins.

enabled

Names of enabled shell builtins.

export

Names of exported shell variables. May also be specified as -e.

file

File and directory names, similar to readline's filename completion. May also be specified as -f.

function

Names of shell functions.

group

Group names. May also be specified as -g.

helptopic

Help topics as accepted by the help builtin.

hostname

Hostnames, as taken from the file specified by the HOSTFILE shell variable.

job

Job names, if job control is active. May also be specified as -j.

keyword

Shell reserved words. May also be specified as -k.

running

Names of running jobs, if job control is active.

service

Service names. May also be specified as -s.

setopt

Valid arguments for the -o option to the set builtin.

shopt

Shell option names as accepted by the shopt builtin.

signal

Signal names.

stopped

Names of stopped jobs, if job control is active.

user

User names. May also be specified as -u.

variable

Names of all shell variables. May also be specified as -v.

+B option or disable brace expansion with the

+B option to the set command (see SHELL BUILTIN COMMANDS below) for strict sh compatibility.

After word splitting, unless the

-f option has been set, bash scans each word for the characters *, ?, and

-v varname

True if the shell variable varname is set (has been assigned a value). If varname is an indexed array variable name subscripted by @ or *, this returns true if the array has any set elements. If varname is an associative array variable name subscripted by @ or *, this returns true if an element with that key is set.

-R varname

True if the shell variable varname is set and is a name reference.

-z string

True if the length of string is zero.

file1 -ef file2

True if file1 and file2 refer to the same device and inode numbers.

file1 -nt file2

True if file1 is newer (according to modification date) than file2, or if file1 exists and file2 does not.

file1 -ot file2

True if file1 is older than file2, or if file2 exists and file1 does not.

OP is one of

-eq, -ne, -lt, -le, -gt, or -ge. These arithmetic binary operators return true if arg1 is equal to, not equal to, less than, less than or equal to, greater than, or greater than or equal to arg2, respectively. arg1 and arg2 may be positive or negative integers. When used with the [[ command, arg1 and arg2 are evaluated as arithmetic expressions (see ARITHMETIC EVALUATION above). Since the expansions the [[ command performs on arg1 and arg2 can potentially result in empty strings, arithmetic expression evaluation treats those as expressions that evaluate to 0.

-b option to the

set builtin command is enabled, bash reports status changes immediately. Bash executes any trap on SIGCHLD for each child that terminates.

The bind -V command lists the current readline variable names and values (see

SHELL BUILTIN COMMANDS below).

First, bash performs the actions specified by the compspec. This only returns matches which are prefixes of the word being completed. When the

-f or -d option is used for filename or directory name completion, bash uses the shell variable FIGNORE to filter the matches.

After these matches have been generated, bash executes any shell function or command specified with the -F and -C options. When the command or function is invoked, bash assigns values to the

COMP_LINE, COMP_POINT, COMP_KEY, and COMP_TYPE variables as described above under Shell Variables. If a shell function is being invoked, bash also sets the COMP_WORDS and COMP_CWORD variables. When the function or command is invoked, the first argument ($1) is the name of the command whose arguments are being completed, the second argument ($2) is the word being completed, and the third argument ($3) is the word preceding the word being completed on the current command line. There is no filtering of the generated completions against the word being completed; the function or command has complete freedom in generating the matches and they do not need to match a prefix of the word.

Any function specified with -F is invoked first. The function may use any of the shell facilities, including the compgen and compopt builtins described below, to generate the matches. It must put the possible completions in the COMPREPLY array variable, one per array element.

Next, any command specified with the -C option is invoked in an environment equivalent to command substitution. It should print a list of completions, one per line, to the standard output. Backslash will escape a newline, if necessary. These are added to the set of possible completions.

Finally, programmable completion adds any prefix and suffix specified with the -P and -S options, respectively, to each completion, and returns the result to readline as the list of possible completions.

History expansion is enabled by default for interactive shells, and can be disabled using the

+H option to the set builtin command (see SHELL BUILTIN COMMANDS below). Non-interactive shells do not perform history expansion by default, but it can be enabled with “set -H”.

History expansion is enabled by default for interactive shells, and can be disabled using the

+H option to the set builtin command (see SHELL BUILTIN COMMANDS below). Non-interactive shells do not perform history expansion by default, but it can be enabled with “set -H”.

-m keymap

Use keymap as the keymap to be affected by the subsequent bindings. Acceptable keymap names are emacs, emacs-standard, emacs-meta, emacs-ctlx, vi, vi-move, vi-command, and vi-insert. vi is equivalent to vi-command (vi-move is also a synonym); emacs is equivalent to emacs-standard.

-S

Display readline key sequences bound to macros and the strings they output.

-u function

Unbind all key sequences bound to the named readline function.

-x keyseq[: ]shell-command

Cause shell-command to be executed whenever keyseq is entered. The separator between keyseq and shell-command is either whitespace or a colon optionally followed by whitespace. If the separator is whitespace, shell-command must be enclosed in double quotes and readline expands any of its special backslash-escapes in shell-command before saving it. If the separator is a colon, any enclosing double quotes are optional, and readline does not expand the command string before saving it. Since the entire key binding expression must be a single argument, it should be enclosed in single quotes. When shell-command is executed, the shell sets the READLINE_LINE variable to the contents of the readline line buffer and the READLINE_POINT and READLINE_MARK variables to the current location of the insertion point and the saved insertion point (the mark), respectively. The shell assigns any numeric argument the user supplied to the READLINE_ARGUMENT variable. If there was no argument, that variable is not set. If the executed command changes the value of any of READLINE_LINE, READLINE_POINT, or READLINE_MARK, those new values will be reflected in the editing state.

-X

List all key sequences bound to shell commands and the associated commands in a format that can be reused as an argument to a subsequent bind command.

The

-L option forces cd to follow symbolic links by resolving the link after processing instances of .. in dir. If .. appears in dir, cd processes it by removing the immediately previous pathname component from dir, back to a slash or the beginning of dir, and verifying that the portion of dir it has processed to that point is still a valid directory name after removing the pathname component. If it is not a valid directory name, cd returns a non-zero status. If neither -L nor -P is supplied, cd behaves as if -L had been supplied.

On systems that support it, the -@ option presents the extended attributes associated with a file as a directory.

If either the

-V or -v option is supplied, command prints a description of command. The -v option displays a single word indicating the command or filename used to invoke command; the -V option produces a more verbose description.

group

Group names. May also be specified as -g.

job

Job names, if job control is active. May also be specified as -j.

keyword

Shell reserved words. May also be specified as -k.

-F function

The shell function function is executed in the current shell environment. When the function is executed, the first argument ($1) is the name of the command whose arguments are being completed, the second argument ($2) is the word being completed, and the third argument ($3) is the word preceding the word being completed on the current command line. When function finishes, programmable completion retrieves the possible completions from the value of the COMPREPLY array variable.

-G globpat

Expand the pathname expansion pattern globpat to generate the possible completions.

-W wordlist

Split the wordlist using the characters in the IFS special variable as delimiters, and expand each resulting word. Shell quoting is honored within wordlist, in order to provide a mechanism for the words to contain shell metacharacters or characters in the value of IFS. The possible completions are the members of the resultant list which match a prefix of the word being completed.

-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

Enable posix mode; change the behavior of bash where the default operation differs from the POSIX standard to match the standard. See SEE ALSO below for a reference to a document that details how posix mode affects bash's behavior.

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, set prints the current shell option settings. If +o is supplied with no option-name, set prints a series of set commands to recreate the current option settings on the standard output.

The -D option indicates that other supplied options should apply to the “default” command completion; the -E option indicates that other supplied options should apply to “empty” command completion; and the -I option indicates that other supplied options should apply to completion on the initial word on the line. These are determined in the same way as the complete builtin.

If multiple options are supplied, the -D option takes precedence over -E, and both take precedence over -I.

The

-I option causes local variables to inherit the attributes (except the nameref attribute) and value of any existing variable with the same name at a surrounding scope. If there is no existing variable, the local variable is initially unset.

**+**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.

If the -h option is supplied, disown does not remove the jobs corresponding to each

id from the jobs table, but rather marks them so the shell does not send SIGHUP to the job if the shell receives a SIGHUP.

-d offset

Delete the history entry at position offset. If offset is negative, it is interpreted as relative to one greater than the last history position, so negative indices count back from the end of the history, and an index of -1 refers to the current history -d command.

-d start-end

Delete the range of history entries between positions start and end, inclusive. Positive and negative values for start and end are interpreted as described above.

-w

Write the current history list to the history file, overwriting the history file.

-s

Store the args in the history list as a single entry. The last command in the history list is removed before adding the args.

Send the signal specified by

sigspec or signum to the processes named by each id. Each id may be a job specification jobspec or a process ID pid. 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 supplied, then kill sends SIGTERM.

The

-l option lists the signal names. If any arguments are supplied when -l is given, kill lists the names of the signals corresponding to the arguments, 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; if it is supplied, kill prints the name of the signal that caused the process to terminate. kill assumes that process exit statuses are greater than 128; anything less than that is a signal number. The -L option is equivalent to -l.

-n

Copy at most count lines. If count is 0, copy all lines.

-O

Begin assigning to array at index origin. The default index is 0.

**+**n

Remove the nth entry counting from the left of the list shown by dirs, starting with zero, from the stack. For example: “popd +0” removes the first directory, “popd +1” the second.

-E

If the standard input is coming from a terminal, read uses readline (see READLINE above) to obtain the line. Readline uses the current (or default, if line editing was not previously active) editing settings, but uses bash's default completion, including programmable completion.

-N nchars

read returns after reading exactly nchars characters rather than waiting for a complete line of input, unless it encounters EOF or read times out. Any delimiter characters in the input are not treated specially and do not cause read to return until it has read nchars characters. The result is not split on the characters in IFS; the intent is that the variable is assigned exactly the characters read (with the exception of backslash; see the -r option below).

-e

Exit immediately if a pipeline (which may consist of a single simple command), a list, or a compound command (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 reserved word, 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 (subject to the state of the pipefail shell option), or if the command's return value is being inverted with !. If a compound command other than a subshell returns a non-zero status because a command failed while -e was being ignored, the shell does not exit. 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.

If a compound command or shell function executes in a context where -e is being ignored, none of the commands executed within the compound command or function body will be affected by the -e setting, even if -e is set and a command returns a failure status. If a compound command or shell function sets -e while executing in a context where -e is ignored, that setting will not have any effect until the compound command or the command containing the function call completes.

-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. Using the redirection operator >| instead of > will override this and force the creation of an output file.

-P

If set, the shell does not resolve 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.

-

Signal the end of options, and assign all remaining args to the positional parameters. The -x and -v options are turned off. If there are no args, the positional parameters remain unchanged.

-q

Suppresses normal output (quiet mode); the return status indicates whether the optname is set or unset. If multiple optname arguments are supplied with -q, the return status is zero if all optnames are enabled; non-zero otherwise.

-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 executable file, respectively. If the name is not found, type prints nothing and returns a non-zero exit status.

If the

-p option is used, type either returns the pathname of the executable file that would be found by searching $PATH for 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 name is present in the table of hashed commands, -p and -P print the hashed value, which is not necessarily the file that appears first in PATH.

The -H and -S options specify whether 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, ulimit sets both the soft and hard limits.

-r option is supplied at invocation, the shell becomes restricted. A restricted shell is used to set up an environment more controlled than the standard shell. It behaves identically to

bash with the exception that the following are disallowed or not performed:

  • Changing directories with cd.

  • Setting or unsetting the values of SHELL, PATH, HISTFILE, ENV, or BASH_ENV.

  • Specifying command names containing /.

  • Specifying a filename containing a / as an argument to the . builtin command.

  • Using the -p option to the . builtin command to specify a search path.

  • Specifying a filename containing a slash as an argument to the history builtin command.

  • Specifying a filename containing a slash as an argument to the -p option to the hash builtin command.

  • Importing function definitions from the shell environment at startup.

  • Parsing the values of BASHOPTS and SHELLOPTS from the shell environment at startup.

  • Redirecting output using the >, >|, <>, >&, &>, and >> redirection operators.

  • Using the exec builtin command to replace the shell with another command.

  • Adding or deleting builtin commands with the -f and -d options to the enable builtin command.

  • Using the enable builtin command to enable disabled shell builtins.

  • Specifying the -p option to the command builtin command.

  • Turning off restricted mode with set +r or shopt -u restricted_shell.

These restrictions are enforced after any startup files are read.

When a command that is found to be a shell script is executed (see COMMAND EXECUTION above), rbash turns off any restrictions in the shell spawned to execute the script.

compat31

  • Quoting the rhs of the [[ command's regexp matching operator (=~) has no special effect.

compat32

  • The < and > operators to the [[ command do not consider the current locale when comparing strings; they use ASCII ordering.

compat40

  • The < and > operators to the [[ command do not consider the current locale when comparing strings; they use ASCII ordering. Bash versions prior to bash-4.1 use ASCII collation and strcmp(3); bash-4.1 and later use the current locale's collation sequence and strcoll(3).

compat41

  • In posix mode, time may be followed by options and still be recognized as a reserved word (this is POSIX interpretation 267).

  • In posix mode, the parser requires that an even number of single quotes occur in the word portion of a double-quoted parameter expansion and treats them specially, so that characters within the single quotes are considered quoted (this is POSIX interpretation 221).

compat42

  • The replacement string in double-quoted pattern substitution does not undergo quote removal, as it does in versions after bash-4.2.

  • In posix mode, single quotes are considered special when expanding the word portion of a double-quoted parameter expansion and can be used to quote a closing brace or other special character (this is part of POSIX interpretation 221); in later versions, single quotes are not special within double-quoted word expansions.

compat43

  • Word expansion errors are considered non-fatal errors that cause the current command to fail, even in posix mode (the default behavior is to make them fatal errors that cause the shell to exit).

  • When executing a shell function, the loop state (while/until/etc.) is not reset, so break or continue in that function will break or continue loops in the calling context. Bash-4.4 and later reset the loop state to prevent this.

compat44

  • The shell sets up the values used by BASH_ARGV and BASH_ARGC so they can expand to the shell's positional parameters even if extended debugging mode is not enabled.

  • A subshell inherits loops from its parent context, so break or continue will cause the subshell to exit. Bash-5.0 and later reset the loop state to prevent the exit

  • Variable assignments preceding builtins like export and readonly that set attributes continue to affect variables with the same name in the calling environment even if the shell is not in posix mode.

compat50

  • Bash-5.1 changed the way $RANDOM is generated to introduce slightly more randomness. If the shell compatibility level is set to 50 or lower, it reverts to the method from bash-5.0 and previous versions, so seeding the random number generator by assigning a value to RANDOM will produce the same sequence as in bash-5.0.

  • If the command hash table is empty, bash versions prior to bash-5.1 printed an informational message to that effect, even when producing output that can be reused as input. Bash-5.1 suppresses that message when the -l option is supplied.

compat51

  • The unset builtin treats attempts to unset array subscripts @ and * differently depending on whether the array is indexed or associative, and differently than in previous versions.

  • Arithmetic commands ( ((...)) ) and the expressions in an arithmetic for statement can be expanded more than once.

  • Expressions used as arguments to arithmetic operators in the [[ conditional command can be expanded more than once.

  • The expressions in substring parameter brace expansion can be expanded more than once.

  • The expressions in the $((...)) word expansion can be expanded more than once.

  • Arithmetic expressions used as indexed array subscripts can be expanded more than once.

  • test -v, when given an argument of A[@], where A is an existing associative array, will return true if the array has any set elements. Bash-5.2 will look for and report on a key named @.

  • The ${parameter**[:]=**value} word expansion will return value, before any variable-specific transformations have been performed (e.g., converting to lowercase). Bash-5.2 will return the final value assigned to the variable.

  • Parsing command substitutions will behave as if extended globbing (see the description of the shopt builtin above) is enabled, so that parsing a command substitution containing an extglob pattern (say, as part of a shell function) will not fail. This assumes the intent is to enable extglob before the command is executed and word expansions are performed. It will fail at word expansion time if extglob hasn't been enabled by the time the command is executed.

compat52

  • The test builtin uses its historical algorithm to parse parenthesized subexpressions when given five or more arguments.

  • If the -p or -P option is supplied to the bind builtin, bind treats any arguments remaining after option processing as bindable command names, and displays any key sequences bound to those commands, instead of treating the arguments as key sequences to bind.