Chapter 3: Basic Shell Features

14

slashes are used both by the shell and regular expressions to remove the special meaning from the following character. The following two sets of commands are not equivalent: pattern=’\.’

[[ . =~ $pattern ]]

[[ . =~ \. ]]

[[ . =~ "$pattern" ]]

[[ . =~ ’\.’ ]]

The first two matches will succeed, but the second two will not, because in the second two the backslash will be part of the pattern to be matched. In the first two examples, the backslash removes the special meaning from ‘.’, so the literal ‘.’ matches. If the string in the first examples were anything other than

‘.’, say ‘a’, the pattern would not match, because the quoted ‘.’ in the pattern loses its special meaning of matching any single character.

Expressions may be combined using the following operators, listed in decreasing order of precedence:

( expression )

Returns the value of expression. This may be used to override the normal precedence of operators.

! expression

True if expression is false. expression1 && expression2

True if both expression1 and expression2 are true. expression1 || expression2

True if either expression1 or expression2 is true.

The && and || operators do not evaluate expression2 if the value of expression1 is sufficient to determine the return value of the entire conditional expression.

3.2.4.3 Grouping Commands

Bash provides two ways to group a list of commands to be executed as a unit. When com- mands are grouped, redirections may be applied to the entire command list. For example, the output of all the commands in the list may be redirected to a single stream.

()

( list )

Placing a list of commands between parentheses causes a subshell environment to be created (see Section 3.7.3 [Command Execution Environment], page 36), and each of the commands in list to be executed in that subshell. Since the list is executed in a subshell, variable assignments do not remain in effect after the subshell completes.

{}