BASH’s compat31 option

Several of my bash scripts failed when I migrated from Debian to Gentoo almost one year ago for the different ways bash interpretes commands like this: [[ "$x" =~ '^[0-9]$' ]]. This command succeeded in Debian when $x is a single digit, but failed in Gentoo. I had to remove the single quotes surround the regular expression to make it work in Gentoo.

Today I finally found the reason: I was using bash 3.1 in Debian and 3.2 in Gentoo. Bash 3.2 by default mandates that regular expressions not be surrounded by quotes; however, the behavior can be modified using shopt -s compat31.


Related posts:

  1. Extended pattern matching in BASH
  2. How BASH Changes Terminal Window Title
  3. globstar in bash 4 follows directory symlinks
  4. Extract Deb files from command line

Tags:

Leave a Reply

*

Hint: Register at Gravatar and your comments will be accompanied by your personalized icon.