10.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.
  • Bash-4.0 and later now allows process substitution constructs to pass unchanged through brace expansion, so any expansion of the contents will have to be separately specified, and each process substitution will have to be separately entered.
  • Bash-4.0 and later now allows SIGCHLD to interrupt the wait builtin, as Posix specifies, so the SIGCHLD trap is no longer always invoked once per exiting child if you are using `wait' to wait for all children.
  • Since Bash-4.0 and later now follows Posix rules for finding the closing delimiter of a $() command substitution, it will not behave as previous versions did, but will catch more syntax and parsing errors before spawning a subshell to evaluate the command substitution.
  • The programmable completion code uses the same set of delimiting characters as readline when breaking the command line into words, rather than the set of shell metacharacters, so programmable completion and readline will be more consistent.
  • When the read builtin times out, it attempts to assign any input read to specified variables, which also causes variables to be set to the empty string if there is not enough input. Previous versions discarded the characters read.
  • In Bash-4.0 and later, when one of the commands in a pipeline is killed by a SIGINT while executing a command list, the shell acts as if it received the interrupt.
  • Bash-4.0 and later versions change the handling of the set -e option so that the shell exits if a pipeline fails (and not just if the last command in the failing pipeline is a simple command). This is not as Posix specifies. There is work underway to update this portion of the standard; the Bash-4.0 behavior attempts to capture the consensus at the time of release.
  • Bash-4.0 and later fixes a Posix mode bug that caused the . (source) builtin to search the current directory for its filename argument, even if "." is not in the system PATH. Posix says that the shell should not look in the PWD variable in this case.
  • Bash-4.1 uses the current locale when comparing strings using operators to the [[ command. This can be reverted to the previous behavior by setting one of the compatNN shopt options.

10.2.1. Regular Expressions

Further to the points already listed, quoting the pattern argument to the regular expression matching conditional operator =~ can 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 operator 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 can 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 can contain whitespace. The first problem is 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.
Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.