Product SiteDocumentation Site

9.2. Bash (Bourne-Again Shell)

Red Hat Enterprise Linux 6 includes version 4.1 of Bash as its default shell. This section describes the compatibility issues that this version introduces over previous versions.
Regular Expressions
Further to the points already listed, quoting the pattern argument to the regular expression matching conditional operator =~ may cause regexp matching to stop working. This occurs on all architectures. In versions of bash prior to 3.2, the effect of quoting the regular expression argument to the [[ command's =~ operator was not specified. The practical effect was that double-quoting the pattern argument required backslashes to quote special pattern characters, which interfered with the backslash processing performed by double-quoted word expansion and was inconsistent with how the == shell pattern matching operator treated quoted characters.
In bash version 3.2, the shell was changed to internally quote characters in single- and double-quoted string arguments to the =~ operator, which suppresses the special meaning of the characters that are important to regular expression processing (`.', `[', `\', `(', `), `*', `+', `?', `{', `|', `^', and `$') and forces them to be matched literally. This is consistent with how the == pattern matching operater treats quoted portions of its pattern argument.
Since the treatment of quoted string arguments was changed, several issues have arisen, chief among them the problem of white space in pattern arguments and the differing treatment of quoted strings between bash 3.1 and bash 3.2. Both problems may be solved by using a shell variable to hold the pattern. Since word splitting is not performed when expanding shell variables in all operands of the [[ command, this provides the ability to quote patterns as you wish when assigning the variable, then expand the values to a single string that may contain whitespace. The first problem may be solved by using backslashes or any other quoting mechanism to escape the white space in the patterns.
Bash 4.0 introduces the concept of a compatibility level, controlled by several options to the shopt builtin. If the compat31 option is enabled, bash will revert to the 3.1 behavior with respect to quoting the right-hand side of the =~ operator.