Bash =~

From NovaOrdis Knowledge Base
Revision as of 20:32, 20 September 2019 by Ovidiu (talk | contribs)
Jump to navigation Jump to search

Internal

Overview

The string to the right of the = ̃ operator is considered an extended regular expression and matched against the string to the left of the operator. The rules governing the extended regular expression are described in regex(3).

if [["string_to_be_matched_against_regex" =~ regex ]]; then
  # match 
else
  # no match 
fi

Usage is subject to the following constraints:

  • The use of [[...]] is required.
  • DO NOT use double quotes when specifying the regular expression, just specify the regex literal directly.