neulab/tldr huggingface dataset:
A sequence expression takes the form {x..y[..incr]}, where x and y are either integers or single characters, and incr, an optional increment, is an integer.  When integers are supplied, the expression expands to each number between x and y, inclusive.  Supplied integers may be prefixed with 0 to force each term to have the same width.  When either x or y begins with a zero, the shell attempts to force all generated terms to contain the same number of digits, zero-padding where necessary.  When characters are supplied, the expression expands to each character lexicographically between x and y, inclusive, using the default C locale. Note that both x and y must be of the same type.  When the increment is supplied, it is used as the difference between each term.  The default increment is 1 or -1 as appropriate.
Brace expansion is performed before any other expansions, and any characters special to other expansions are preserved in the result.  It is strictly textual.  Bash does not apply any syntactic interpretation to the context of the expansion or the text between the braces.
A correctly-formed brace expansion must contain unquoted opening and closing braces, and at least one unquoted comma or a valid sequence expression.  Any incorrectly formed brace expansion is left unchanged.  A { or , may be quoted with a backslash to prevent its being considered part of a brace expression.  To avoid conflicts with parameter expansion, the string ${ is not considered eligible for brace expansion, and inhibits brace expansion until the closing }.
This construct is typically used as shorthand when the common prefix of the strings to be generated is longer than in the above example:
mkdir /usr/local/src/bash/{old,new,dist,bugs} or chown root /usr/{ucb/{ex,edit},lib/{ex?.?*,how_ex}}
Brace expansion introduces a slight incompatibility with historical versions of sh.  sh does not treat opening or closing braces specially when they appear as part of a word, and preserves them in the output. Bash removes braces from words as a consequence of brace expansion.  For example, a word entered to sh as file{1,2} appears identically in the output.  The same word is output as file1 file2 after expansion by bash. If strict compatibility with sh is desired, start bash with the +B option or disable brace expansion with the +B option to the set command (see SHELL BUILTIN COMMANDS below).
Tilde Expansion If a word begins with an unquoted tilde character (`~'), all of the characters preceding the first unquoted slash (or all characters, if there is no unquoted slash) are considered a tilde-prefix.  If none of the characters in the tilde-prefix are quoted, the characters in the tilde-prefix following the tilde are treated as a possible login name. If this login name is the null string, the tilde is replaced with the value of the shell parameter HOME.  If HOME is unset, the home directory of the user executing the shell is substituted instead.  Otherwise, the tilde-prefix is replaced with the home directory associated with the specified login name.
If the tilde-prefix is a `~+', the value of the shell variable PWD replaces the tilde-prefix.  If the tilde-prefix is a `~-', the value of the shell variable OLDPWD, if it is set, is substituted.  If the characters following the tilde in the tilde-prefix consist of a number N, optionally prefixed by a `+' or a `-', the tilde-prefix is replaced with the corresponding element from the directory stack, as it would be displayed by the dirs builtin invoked with the tilde-prefix as an argument.  If the characters following the tilde in the tilde-prefix consist of a number without a leading `+' or `-', `+' is assumed.
If the login name is invalid, or the tilde expansion fails, the word is unchanged.
Each variable assignment is checked for unquoted tilde-prefixes immediately following a : or the first =.  In these cases, tilde expansion is also performed.  Consequently, one may use filenames with tildes in assignments to PATH, MAILPATH, and CDPATH, and the shell assigns the expanded value.
Bash also performs tilde expansion on words satisfying the conditions of variable assignments (as described above under PARAMETERS) when they appear as arguments to simple commands.  Bash does not do this, except for the declaration commands listed above, when in posix mode.
Parameter Expansion The `$' character introduces parameter expansion, command substitution, or arithmetic expansion.  The parameter name or symbol to be expanded may be enclosed in braces, which are optional but serve to protect the variable to be expanded from characters immediately following it which could be interpreted as part of the name.
When braces are used, the matching ending brace is the first `}' not escaped by a backslash or within a quoted string, and not within an embedded arithmetic expansion, command substitution, or parameter expansion.
${parameter} The value of parameter is substituted.  The braces are required when parameter is a positional parameter with more than one digit, or when parameter is followed by a character which is not to be interpreted as part of its name.  The parameter is a shell parameter as described above PARAMETERS) or an array reference (Arrays).
If the first character of parameter is an exclamation point (!), and parameter is not a nameref, it introduces a level of indirection.  Bash uses the value formed by expanding the rest of parameter as the new parameter; this is then expanded and that value is used in the rest of the expansion, rather than the expansion of the original parameter.  This is known as indirect expansion.  The value is subject to tilde expansion, parameter expansion, command substitution, and arithmetic expansion.  If parameter is a nameref, this expands to the name of the parameter referenced by parameter instead of performing the complete indirect expansion.  The exceptions to this are the expansions of ${!prefix*} and ${!name[@]} described below.  The exclamation point must immediately follow the left brace in order to introduce indirection.
In each of the cases below, word is subject to tilde expansion, parameter expansion, command substitution, and arithmetic expansion.
When not performing substring expansion, using the forms documented below (e.g., :-), bash tests for a parameter that is unset or null.  Omitting the colon results in a test only for a parameter that is unset.
${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.  The value of parameter is then substituted.  Positional parameters and special parameters may not be assigned to in this way. ${parameter:?word} Display Error if Null or Unset.  If parameter is null or unset, the expansion of word (or a message to that effect if word is not present) is written to the standard error and the shell, if it is not interactive, exits.  Otherwise, the value of parameter is substituted. ${parameter:+word} Use Alternate Value.  If parameter is null or unset, nothing is substituted, otherwise the expansion of word is substituted. ${parameter:offset} ${parameter:offset:length} Substring Expansion.  Expands to up to length characters of the value of parameter starting at the character specified by offset. If parameter is @, an indexed array subscripted by @ or *, or an associative array name, the results differ as described below.  If length is omitted, expands to the substring of the value of parameter starting at the character specified by offset and extending to the end of the value.  length and offset are arithmetic expressions (see ARITHMETIC EVALUATION below).
If offset evaluates to a number less than zero, the value is used as an offset in characters from the end of the value of parameter. If length evaluates to a number less than zero, it is interpreted as an offset in characters from the end of the value of parameter rather than a number of characters, and the expansion is the characters between offset and that result.  Note that a negative offset must be separated from the colon by at least one space to avoid being confused with the :- expansion.
If parameter is @, the result is length positional parameters beginning at offset.  A negative offset is taken relative to one greater than the greatest positional parameter, so an offset of -1 evaluates to the last positional parameter.  It is an expansion error if length evaluates to a number less than zero.
If parameter is an indexed array name subscripted by @ or *, the result is the length members of the array beginning with ${parameter[offset]}.  A negative offset is taken relative to one greater than the maximum index of the specified array.  It is an expansion error if length evaluates to a number less than zero.
Substring expansion applied to an associative array produces undefined results.
Substring indexing is zero-based unless the positional parameters are used, in which case the indexing starts at 1 by default.  If offset is 0, and the positional parameters are used, $0 is prefixed to the list.
${!prefix*} ${!prefix@} Names matching prefix.  Expands to the names of variables whose names begin with prefix, separated by the first character of the IFS special variable.  When @ is used and the expansion appears within double quotes, each variable name expands to a separate word.
${!name[@]} ${!name[*]} List of array keys.  If name is an array variable, expands to the list of array indices (keys) assigned in name.  If name is not an array, expands to 0 if name is set and null otherwise.  When @ is used and the expansion appears within double quotes, each key expands to a separate word.
${#parameter} Parameter length.  The length in characters of the value of parameter is substituted.  If parameter is * or @, the value substituted is the number of positional parameters.  If parameter is an array name subscripted by * or @, the value substituted is the number of elements in the array.  If parameter is an indexed array name subscripted by a negative number, that number is interpreted as relative to one greater than the maximum index of parameter, so negative indices count back from the end of the array, and an index of -1 references the last element.
${parameter#word} ${parameter##word} Remove matching prefix pattern.  The word is expanded to produce a pattern just as in pathname expansion, and matched against the expanded value of parameter using the rules described under Pattern Matching below.  If the pattern matches the beginning of the value of parameter, then the result of the expansion is the expanded value of parameter with the shortest matching pattern (the ``#'' case) or the longest matching pattern (the ``##'' case) deleted.  If parameter is @ or *, the pattern removal operation is applied to each positional parameter in turn, and the expansion is the resultant list.  If parameter is an array variable subscripted with @ or *, the pattern removal operation is applied to each member of the array in turn, and the expansion is the resultant list.
${parameter%word} ${parameter%%word} Remove matching suffix pattern.  The word is expanded to produce a pattern just as in pathname expansion, and matched against the expanded value of parameter using the rules described under Pattern Matching below.  If the pattern matches a trailing portion of the expanded value of parameter, then the result of the expansion is the expanded value of parameter with the shortest matching pattern (the ``%'' case) or the longest matching pattern (the ``%%'' case) deleted.  If parameter is @ or *, the pattern removal operation is applied to each positional parameter in turn, and the expansion is the resultant list.  If parameter is an array variable subscripted with @ or *, the pattern removal operation is applied to each member of the array in turn, and the expansion is the resultant list.
${parameter/pattern/string} Pattern substitution.  The pattern is expanded to produce a pattern just as in pathname expansion, Parameter is expanded and the longest match of pattern against its value is replaced with string.  The match is performed using the rules described under Pattern Matching below.  If pattern begins with /, all matches of pattern are replaced with string.  Normally only the first match is replaced.  If pattern begins with #, it must match at the beginning of the expanded value of parameter.  If pattern begins with %, it must match at the end of the expanded value of parameter.  If string is null, matches of pattern are deleted and the / following pattern may be omitted.  If the nocasematch shell option is enabled, the match is performed without regard to the case of alphabetic characters.  If parameter is @ or *, the substitution operation is applied to each positional parameter in turn, and the expansion is the resultant list.  If parameter is an array variable subscripted with @ or *, the substitution operation is applied to each member of the array in turn, and the expansion is the resultant list.
${parameter^pattern} ${parameter^^pattern} ${parameter,pattern} ${parameter,,pattern} Case modification.  This expansion modifies the case of alphabetic characters in parameter.  The pattern is expanded to produce a pattern just as in pathname expansion.  Each character in the expanded value of parameter is tested against pattern, and, if it matches the pattern, its case is converted.  The pattern should not attempt to match more than one character.  The ^ operator converts lowercase letters matching pattern to uppercase; the , operator converts matching uppercase letters to lowercase.  The ^^ and ,, expansions convert each matched character in the expanded value; the ^ and , expansions match and convert only the first character in the expanded value.  If pattern is omitted, it is treated like a ?, which matches every character.  If parameter is @ or *, the case modification operation is applied to each positional parameter in turn, and the expansion is the resultant list.  If parameter is an array variable subscripted with @ or *, the case modification operation is applied to each member of the array in turn, and the expansion is the resultant list.
${parameter@operator} Parameter transformation.  The expansion is either a transformation of the value of parameter or information about parameter itself, depending on the value of operator.  Each operator is a single letter:
U      The expansion is a string that is the value of parameter with lowercase alphabetic characters converted to uppercase. u      The expansion is a string that is the value of parameter with the first character converted to uppercase, if it is alphabetic. L      The expansion is a string that is the value of parameter with uppercase alphabetic characters converted to lowercase. Q      The expansion is a string that is the value of parameter quoted in a format that can be reused as input. E      The expansion is a string that is the value of parameter with backslash escape sequences expanded as with the $'...' quoting mechanism. P      The expansion is a string that is the result of expanding the value of parameter as if it were a prompt string (see PROMPTING below). A      The expansion is a string in the form of an assignment statement or declare command that, if evaluated, will recreate parameter with its attributes and value. K      Produces a possibly-quoted version of the value of parameter, except that it prints the values of indexed and associative arrays as a sequence of quoted key-value pairs (see Arrays above). a      The expansion is a string consisting of flag values representing parameter's attributes.
If parameter is @ or *, the operation is applied to each positional parameter in turn, and the expansion is the resultant list.  If parameter is an array variable subscripted with @ or *, the operation is applied to each member of the array in turn, and the expansion is the resultant list.
The result of the expansion is subject to word splitting and pathname expansion as described below.
Command Substitution Command substitution allows the output of a command to replace the command name.  There are two forms:
$(command) or `command`
Bash performs the expansion by executing command in a subshell environment and replacing the command substitution with the standard output of the command, with any trailing newlines deleted.  Embedded newlines are not deleted, but they may be removed during word splitting. The command substitution $(cat file) can be replaced by the equivalent but faster $(< file).
When the old-style backquote form of substitution is used, backslash retains its literal meaning except when followed by $, `, or \.  The first backquote not preceded by a backslash terminates the command substitution.  When using the $(command) form, all characters between the parentheses make up the command; none are treated specially.
Command substitutions may be nested.  To nest when using the backquoted form, escape the inner backquotes with backslashes.
If the substitution appears within double quotes, word splitting and pathname expansion are not performed on the results.
Arithmetic Expansion Arithmetic expansion allows the evaluation of an arithmetic expression and the substitution of the result.  The format for arithmetic expansion is:
The expression is treated as if it were within double quotes, but a double quote inside the parentheses is not treated specially.  All tokens in the expression undergo parameter and variable expansion, command substitution, and quote removal.  The result is treated as the arithmetic expression to be evaluated.  Arithmetic expansions may be nested.
The evaluation is performed according to the rules listed below under ARITHMETIC EVALUATION.  If expression is invalid, bash prints a message indicating failure and no substitution occurs.
Process Substitution Process substitution allows a process's input or output to be referred to using a filename.  It takes the form of <(list) or >(list).  The process list is run asynchronously, and its input or output appears as a filename.  This filename is passed as an argument to the current command as the result of the expansion.  If the >(list) form is used, writing to the file will provide input for list.  If the <(list) form is used, the file passed as an argument should be read to obtain the output of list. Process substitution is supported on systems that support named pipes (FIFOs) or the /dev/fd method of naming open files.
When available, process substitution is performed simultaneously with parameter and variable expansion, command substitution, and arithmetic expansion.
Word Splitting The shell scans the results of parameter expansion, command substitution, and arithmetic expansion that did not occur within double quotes for word splitting.
The shell treats each character of IFS as a delimiter, and splits the results of the other expansions into words using these characters as field terminators.  If IFS is unset, or its value is exactly <space><tab><newline>, the default, then sequences of <space>, <tab>, and <newline> at the beginning and end of the results of the previous expansions are ignored, and any sequence of IFS characters not at the beginning or end serves to delimit words.  If IFS has a value other than the default, then sequences of the whitespace characters space, tab, and newline are ignored at the beginning and end of the word, as long as the whitespace character is in the value of IFS (an IFS whitespace character).  Any character in IFS that is not IFS whitespace, along with any adjacent IFS whitespace characters, delimits a field.  A sequence of IFS whitespace characters is also treated as a delimiter.  If the value of IFS is null, no word splitting occurs.
Explicit null arguments ("" or '') are retained and passed to commands as empty strings.  Unquoted implicit null arguments, resulting from the expansion of parameters that have no values, are removed.  If a parameter with no value is expanded within double quotes, a null argument results and is retained and passed to a command as an empty string.  When a quoted null argument appears as part of a word whose expansion is non- null, the null argument is removed.  That is, the word -d'' becomes -d after word splitting and null argument removal.
Note that if no expansion occurs, no splitting is performed.
Pathname Expansion After word splitting, unless the -f option has been set, bash scans each word for the characters *, ?, and [.  If one of these characters appears, and is not quoted, then the word is regarded as a pattern, and replaced with an alphabetically sorted list of filenames matching the pattern (see Pattern Matching below).  If no matching filenames are found, and the shell option nullglob is not enabled, the word is left unchanged.  If the nullglob option is set, and no matches are found, the word is removed. If the failglob shell option is set, and no matches are found, an error message is printed and the command is not executed.  If the shell option nocaseglob is enabled, the match is performed without regard to the case of alphabetic characters.  When a pattern is used for pathname expansion, the character ``.''  at the start of a name or immediately following a slash must be matched explicitly, unless the shell option dotglob is set. The filenames ``.''  and ``..''  must always be matched explicitly, even if dotglob is set.  In other cases, the ``.''  character is not treated specially.  When matching a pathname, the slash character must always be matched explicitly by a slash in the pattern, but in other matching contexts it can be matched by a special pattern character as described below under Pattern Matching.  See the description of shopt below under SHELL BUILTIN COMMANDS for a description of the nocaseglob, nullglob, failglob, and dotglob shell options.
The GLOBIGNORE shell variable may be used to restrict the set of file names matching a pattern.  If GLOBIGNORE is set, each matching file name that also matches one of the patterns in GLOBIGNORE is removed from the list of matches.  If the nocaseglob option is set, the matching against the patterns in GLOBIGNORE is performed without regard to case.  The filenames ``.''  and ``..''  are always ignored when GLOBIGNORE is set and not null.  However, setting GLOBIGNORE to a non-null value has the effect of enabling the dotglob shell option, so all other filenames beginning with a ``.''  will match.  To get the old behavior of ignoring filenames beginning with a ``.'', make ``.*''  one of the patterns in GLOBIGNORE.  The dotglob option is disabled when GLOBIGNORE is unset. The pattern matching honors the setting of the extglob shell option.
Any character that appears in a pattern, other than the special pattern characters described below, matches itself.  The NUL character may not occur in a pattern.  A backslash escapes the following character; the escaping backslash is discarded when matching.  The special pattern characters must be quoted if they are to be matched literally.
The special pattern characters have the following meanings:
*      Matches any string, including the null string.  When the globstar shell option is enabled, and * is used in a pathname expansion context, two adjacent *s used as a single pattern will match all files and zero or more directories and subdirectories.  If followed by a /, two adjacent *s will match only directories and subdirectories. ?      Matches any single character. [...]  Matches any one of the enclosed characters.  A pair of characters separated by a hyphen denotes a range expression; any character that falls between those two characters, inclusive, using the current locale's collating sequence and character set, is matched.  If the first character following the [ is a !  or a ^ then any character not enclosed is matched.  The sorting order of characters in range expressions is determined by the current locale and the values of the LC_COLLATE or LC_ALL shell variables, if set.  To obtain the traditional interpretation of range expressions, where [a-d] is equivalent to [abcd], set value of the LC_ALL shell variable to C, or enable the globasciiranges shell option.  A - may be matched by including it as the first or last character in the set.  A ] may be matched by including it as the first character in the set.
Within [ and ], character classes can be specified using the syntax [:class:], where class is one of the following classes defined in the POSIX standard: alnum alpha ascii blank cntrl digit graph lower print punct space upper word xdigit A character class matches any character belonging to that class.  The word character class matches letters, digits, and the character _.
Within [ and ], an equivalence class can be specified using the syntax [=c=], which matches all characters with the same collation weight (as defined by the current locale) as the character c.
Within [ and ], the syntax [.symbol.] matches the collating symbol symbol.
If the extglob shell option is enabled using the shopt builtin, several extended pattern matching operators are recognized.  In the following description, a pattern-list is a list of one or more patterns separated by a |.  Composite patterns may be formed using one or more of the following sub-patterns:
?(pattern-list) Matches zero or one occurrence of the given patterns *(pattern-list) Matches zero or more occurrences of the given patterns +(pattern-list) Matches one or more occurrences of the given patterns @(pattern-list) Matches one of the given patterns !(pattern-list) Matches anything except one of the given patterns
Complicated extended pattern matching against long strings is slow, especially when the patterns contain alternations and the strings contain multiple matches.  Using separate matches against shorter strings, or using arrays of strings instead of a single long string, may be faster.
Quote Removal After the preceding expansions, all unquoted occurrences of the characters \, ', and " that did not result from one of the above expansions are removed.
Before a command is executed, its input and output may be redirected using a special notation interpreted by the shell.  Redirection allows commands' file handles to be duplicated, opened, closed, made to refer to different files, and can change the files the command reads from and writes to.  Redirection may also be used to modify file handles in the current shell execution environment.  The following redirection operators may precede or appear anywhere within a simple command or may follow a command.  Redirections are processed in the order they appear, from left to right.
Each redirection that may be preceded by a file descriptor number may instead be preceded by a word of the form {varname}.  In this case, for each redirection operator except >&- and <&-, the shell will allocate a file descriptor greater than or equal to 10 and assign it to varname.  If >&- or <&- is preceded by {varname}, the value of varname defines the file descriptor to close.  If {varname} is supplied, the redirection persists beyond the scope of the command, allowing the shell programmer to manage the file descriptor himself.
In the following descriptions, if the file descriptor number is omitted, and the first character of the redirection operator is <, the redirection refers to the standard input (file descriptor 0).  If the first character of the redirection operator is >, the redirection refers to the standard output (file descriptor 1).
The word following the redirection operator in the following descriptions, unless otherwise noted, is subjected to brace expansion, tilde expansion, parameter and variable expansion, command substitution, arithmetic expansion, quote removal, pathname expansion, and word splitting.  If it expands to more than one word, bash reports an error.
Note that the order of redirections is significant.  For example, the command
ls > dirlist 2>&1
directs both standard output and standard error to the file dirlist, while the command
ls 2>&1 > dirlist
directs only the standard output to file dirlist, because the standard error was duplicated from the standard output before the standard output was redirected to dirlist.
Bash handles several filenames specially when they are used in redirections, as described in the following table.  If the operating system on which bash is running provides these special files, bash will use them; otherwise it will emulate them internally with the behavior described below.
/dev/fd/fd If fd is a valid integer, file descriptor fd is duplicated. /dev/stdin File descriptor 0 is duplicated. /dev/stdout File descriptor 1 is duplicated. /dev/stderr File descriptor 2 is duplicated. /dev/tcp/host/port If host is a valid hostname or Internet address, and port is an integer port number or service name, bash attempts to open the corresponding TCP socket. /dev/udp/host/port If host is a valid hostname or Internet address, and port is an integer port number or service name, bash attempts to open the corresponding UDP socket.
A failure to open or create a file causes the redirection to fail.
Redirections using file descriptors greater than 9 should be used with care, as they may conflict with file descriptors the shell uses internally.
Redirecting Input Redirection of input causes the file whose name results from the expansion of word to be opened for reading on file descriptor n, or the standard input (file descriptor 0) if n is not specified.
The general format for redirecting input is:
[n]<word
Redirecting Output Redirection of output causes the file whose name results from the expansion of word to be opened for writing on file descriptor n, or the standard output (file descriptor 1) if n is not specified.  If the file does not exist it is created; if it does exist it is truncated to zero size.
The general format for redirecting output is:
[n]>word
If the redirection operator is >, and the noclobber option to the set builtin has been enabled, the redirection will fail if the file whose name results from the expansion of word exists and is a regular file.  If the redirection operator is >|, or the redirection operator is > and the noclobber option to the set builtin command is not enabled, the redirection is attempted even if the file named by word exists.
Appending Redirected Output Redirection of output in this fashion causes the file whose name results from the expansion of word to be opened for appending on file descriptor n, or the standard output (file descriptor 1) if n is not specified.  If the file does not exist it is created.
The general format for appending output is:
[n]>>word
Redirecting Standard Output and Standard Error This construct allows both the standard output (file descriptor 1) and the standard error output (file descriptor 2) to be redirected to the file whose name is the expansion of word.
There are two formats for redirecting standard output and standard error:
&>word and >&word
Of the two forms, the first is preferred.  This is semantically equivalent to
>word 2>&1
When using the second form, word may not expand to a number or -.  If it does, other redirection operators apply (see Duplicating File Descriptors below) for compatibility reasons.
Appending Standard Output and Standard Error This construct allows both the standard output (file descriptor 1) and the standard error output (file descriptor 2) to be appended to the file whose name is the expansion of word.
The format for appending standard output and standard error is:
&>>word
This is semantically equivalent to
>>word 2>&1
(see Duplicating File Descriptors below).
Here Documents This type of redirection instructs the shell to read input from the current source until a line containing only delimiter (with no trailing blanks) is seen.  All of the lines read up to that point are then used as the standard input (or file descriptor n if n is specified) for a command.
The format of here-documents is:
[n]<<[-]word here-document delimiter
No parameter and variable expansion, command substitution, arithmetic expansion, or pathname expansion is performed on word.  If any part of word is quoted, the delimiter is the result of quote removal on word, and the lines in the here-document are not expanded.  If word is unquoted, all lines of the here-document are subjected to parameter expansion, command substitution, and arithmetic expansion, the character sequence \<newline> is ignored, and \ must be used to quote the characters \, $, and `.
If the redirection operator is <<-, then all leading tab characters are stripped from input lines and the line containing delimiter.  This allows here-documents within shell scripts to be indented in a natural fashion.
Here Strings A variant of here documents, the format is:
[n]<<<word
The word undergoes tilde expansion, parameter and variable expansion, command substitution, arithmetic expansion, and quote removal.  Pathname expansion and word splitting are not performed.  The result is supplied as a single string, with a newline appended, to the command on its standard input (or file descriptor n if n is specified).
Duplicating File Descriptors The redirection operator
[n]<&word
is used to duplicate input file descriptors.  If word expands to one or more digits, the file descriptor denoted by n is made to be a copy of that file descriptor.  If the digits in word do not specify a file descriptor open for input, a redirection error occurs.  If word evaluates to -, file descriptor n is closed.  If n is not specified, the standard input (file descriptor 0) is used.
The operator
[n]>&word
is used similarly to duplicate output file descriptors.  If n is not specified, the standard output (file descriptor 1) is used.  If the digits in word do not specify a file descriptor open for output, a redirection error occurs.  If word evaluates to -, file descriptor n is closed.  As a special case, if n is omitted, and word does not expand to one or more digits or -, the standard output and standard error are redirected as described previously.
Moving File Descriptors The redirection operator
[n]<&digit-
moves the file descriptor digit to file descriptor n, or the standard input (file descriptor 0) if n is not specified.  digit is closed after being duplicated to n.
Similarly, the redirection operator
[n]>&digit-
moves the file descriptor digit to file descriptor n, or the standard output (file descriptor 1) if n is not specified.
Opening File Descriptors for Reading and Writing The redirection operator
[n]<>word
causes the file whose name is the expansion of word to be opened for both reading and writing on file descriptor n, or on file descriptor 0 if n is not specified.  If the file does not exist, it is created.
Aliases allow a string to be substituted for a word when it is used as the first word of a simple command.  The shell maintains a list of aliases that may be set and unset with the alias and unalias builtin commands (see SHELL BUILTIN COMMANDS below).  The first word of each simple command, if unquoted, is checked to see if it has an alias.  If so, that word is replaced by the text of the alias.  The characters /, $, `, and = and any of the shell metacharacters or quoting characters listed above may not appear in an alias name.  The replacement text may contain any valid shell input, including shell metacharacters.  The first word of the replacement text is tested for aliases, but a word that is identical to an alias being expanded is not expanded a second time.  This means that one may alias ls to ls -F, for instance, and bash does not try to recursively expand the replacement text.  If the last character of the alias value is a blank, then the next command word following the alias is also checked for alias expansion.
Aliases are created and listed with the alias command, and removed with the unalias command.
There is no mechanism for using arguments in the replacement text.  If arguments are needed, a shell function should be used (see FUNCTIONS below).
Aliases are not expanded when the shell is not interactive, unless the expand_aliases shell option is set using shopt (see the description of shopt under SHELL BUILTIN COMMANDS below).
The rules concerning the definition and use of aliases are somewhat confusing.  Bash always reads at least one complete line of input, and all lines that make up a compound command, before executing any of the commands on that line or the compound command.  Aliases are expanded when a command is read, not when it is executed.  Therefore, an alias definition appearing on the same line as another command does not take effect until the next line of input is read.  The commands following the alias definition on that line are not affected by the new alias.  This behavior is also an issue when functions are executed.  Aliases are expanded when a function definition is read, not when the function is executed, because a function definition is itself a command.  As a consequence, aliases defined in a function are not available until after that function is executed.  To be safe, always put alias definitions on a separate line, and do not use alias in compound commands.
For almost every purpose, aliases are superseded by shell functions.
A shell function, defined as described above under SHELL GRAMMAR, stores a series of commands for later execution.  When the name of a shell function is used as a simple command name, the list of commands associated with that function name is executed.  Functions are executed in the context of the current shell; no new process is created to interpret them (contrast this with the execution of a shell script). When a function is executed, the arguments to the function become the positional parameters during its execution.  The special parameter # is updated to reflect the change.  Special parameter 0 is unchanged.  The first element of the FUNCNAME variable is set to the name of the function while the function is executing.
All other aspects of the shell execution environment are identical between a function and its caller with these exceptions: the DEBUG and RETURN traps (see the description of the trap builtin under SHELL BUILTIN COMMANDS below) are not inherited unless the function has been given the trace attribute (see the description of the declare builtin below) or the -o functrace shell option has been enabled with the set builtin (in which case all functions inherit the DEBUG and RETURN traps), and the ERR trap is not inherited unless the -o errtrace shell option has been enabled.
Variables local to the function may be declared with the local builtin command.  Ordinarily, variables and their values are shared between the function and its caller.  If a variable is declared local, the variable's visible scope is restricted to that function and its children (including the functions it calls).  Local variables "shadow" variables with the same name declared at previous scopes.  For instance, a local variable declared in a function hides a global variable of the same name: references and assignments refer to the local variable, leaving the global variable unmodified.  When the function returns, the global variable is once again visible.
The shell uses dynamic scoping to control a variable's visibility within functions.  With dynamic scoping, visible variables and their values are a result of the sequence of function calls that caused execution to reach the current function.  The value of a variable that a function sees depends on its value within its caller, if any, whether that caller is the "global" scope or another shell function.  This is also the value that a local variable declaration "shadows", and the value that is restored when the function returns.
For example, if a variable var is declared as local in function func1, and func1 calls another function func2, references to var made from within func2 will resolve to the local variable var from func1, shadowing any global variable named var.
The unset builtin also acts using the same dynamic scope: if a variable is local to the current scope, unset will unset it; otherwise the unset will refer to the variable found in any calling scope as described above. If a variable at the current local scope is unset, it will remain so until it is reset in that scope or until the function returns.  Once the function returns, any instance of the variable at a previous scope will become visible.  If the unset acts on a variable at a previous scope, any instance of a variable with that name that had been shadowed will become visible.
The FUNCNEST variable, if set to a numeric value greater than 0, defines a maximum function nesting level.  Function invocations that exceed the limit cause the entire command to abort.
If the builtin command return is executed in a function, the function completes and execution resumes with the next command after the function call.  Any command associated with the RETURN trap is executed before execution resumes.  When a function completes, the values of the positional parameters and the special parameter # are restored to the values they had prior to the function's execution.
Function names and definitions may be listed with the -f option to the declare or typeset builtin commands.  The -F option to declare or typeset will list the function names only (and optionally the source file and line number, if the extdebug shell option is enabled).  Functions may be exported so that subshells automatically have them defined with the -f option to the export builtin.  A function definition may be deleted using the -f option to the unset builtin.
Functions may be recursive.  The FUNCNEST variable may be used to limit the depth of the function call stack and restrict the number of function invocations.  By default, no limit is imposed on the number of recursive calls.
The shell allows arithmetic expressions to be evaluated, under certain circumstances (see the let and declare builtin commands, the (( compound command, and Arithmetic Expansion).  Evaluation is done in fixed-width integers with no check for overflow, though division by 0 is trapped and flagged as an error.  The operators and their precedence, associativity, and values are the same as in the C language.  The following list of operators is grouped into levels of equal-precedence operators.  The levels are listed in order of decreasing precedence.
id++ id-- variable post-increment and post-decrement - +    unary minus and plus ++id --id variable pre-increment and pre-decrement ! ~    logical and bitwise negation **     exponentiation * / %  multiplication, division, remainder + -    addition, subtraction << >>  left and right bitwise shifts <= >= < > comparison == !=  equality and inequality &      bitwise AND ^      bitwise exclusive OR |      bitwise OR &&     logical AND ||     logical OR expr?expr:expr conditional operator = *= /= %= += -= <<= >>= &= ^= |= assignment expr1 , expr2 comma
Shell variables are allowed as operands; parameter expansion is performed before the expression is evaluated.  Within an expression, shell variables may also be referenced by name without using the parameter expansion syntax.  A shell variable that is null or unset evaluates to 0 when referenced by name without using the parameter expansion syntax. The value of a variable is evaluated as an arithmetic expression when it is referenced, or when a variable which has been given the integer attribute using declare -i is assigned a value.  A null value evaluates to 0.  A shell variable need not have its integer attribute turned on to be used in an expression.
Integer constants follow the C language definition, without suffixes or character constants.  Constants with a leading 0 are interpreted as octal numbers.  A leading 0x or 0X denotes hexadecimal.  Otherwise, numbers take the form [base#]n, where the optional base is a decimal number between 2 and 64 representing the arithmetic base, and n is a number in that base.  If base# is omitted, then base 10 is used.  When specifying n, if a non-digit is required, the digits greater than 9 are represented by the lowercase letters, the uppercase letters, @, and _, in that order. If base is less than or equal to 36, lowercase and uppercase letters may be used interchangeably to represent numbers between 10 and 35.
Operators are evaluated in order of precedence.  Sub-expressions in parentheses are evaluated first and may override the precedence rules above.
Conditional expressions are used by the [[ compound command and the test and [ builtin commands to test file attributes and perform string and arithmetic comparisons.  The test and [ commands determine their behavior based on the number of arguments; see the descriptions of those commands for any other command-specific actions.
Expressions are formed from the following unary or binary primaries. Bash handles several filenames specially when they are used in expressions.  If the operating system on which bash is running provides these special files, bash will use them; otherwise it will emulate them internally with this behavior: If any file argument to one of the primaries is of the form /dev/fd/n, then file descriptor n is checked. If the file argument to one of the primaries is one of /dev/stdin, /dev/stdout, or /dev/stderr, file descriptor 0, 1, or 2, respectively, is checked.
Unless otherwise specified, primaries that operate on files follow symbolic links and operate on the target of the link, rather than the link itself.
When used with [[, the < and > operators sort lexicographically using the current locale.  The test command sorts using ASCII ordering.
-a file True if file exists. -b file True if file exists and is a block special file. -c file True if file exists and is a character special file. -d file True if file exists and is a directory. -e file True if file exists. -f file True if file exists and is a regular file. -g file True if file exists and is set-group-id. -h file True if file exists and is a symbolic link. -k file True if file exists and its ``sticky'' bit is set. -p file True if file exists and is a named pipe (FIFO). -r file True if file exists and is readable. -s file True if file exists and has a size greater than zero. -t fd  True if file descriptor fd is open and refers to a terminal. -u file True if file exists and its set-user-id bit is set. -w file True if file exists and is writable. -x file True if file exists and is executable. -G file True if file exists and is owned by the effective group id. -L file True if file exists and is a symbolic link. -N file True if file exists and has been modified since it was last read. -O file True if file exists and is owned by the effective user id. -S file True if file exists and is a socket. 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. -o optname True if the shell option optname is enabled.  See the list of options under the description of the -o option to the set builtin below. -v varname True if the shell variable varname is set (has been assigned a value). -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. string -n string True if the length of string is non-zero.
string1 == string2 string1 = string2 True if the strings are equal.  = should be used with the test command for POSIX conformance.  When used with the [[ command, this performs pattern matching as described above (Compound Commands).
string1 != string2 True if the strings are not equal.
string1 < string2 True if string1 sorts before string2 lexicographically.
string1 > string2 True if string1 sorts after string2 lexicographically.
arg1 OP arg2 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).
When a simple command is executed, the shell performs the following expansions, assignments, and redirections, from left to right, in the following order.
1.     The words that the parser has marked as variable assignments (those preceding the command name) and redirections are saved for later processing.