From Wiki
Jump to: navigation, search

Bash Programming


[[ vs [

There are quite a few differences, but here are some that are important to me:

  • == and != perform pattern matching, so the right-hand side can be a glob pattern
  • =~ and !~ perform regular expression matching. Captured groups are stored in the BASH_REMATCH array.
  • boolean operators && and ||
  • no word splitting, so it's not strictly necessary to quote your variables.

[[ is understood by KornShell, Zsh and BASH (e.g. 2.03), but not by other POSIX shell implementations (like posh, yash or dash) or the BourneShell .