Comparing !=
and =~
is like comparing apples to oranges.
!=
roughly means "not equal", while =~
means "matches".
You can read more about this operators under [[ expression ]]
in man bash
. Here's an excerpt of the most relevant sections:
When the == and != operators are used, the string to the right of
the operator is considered a pattern and matched according to the
rules described below under Pattern Matching, as if the extglob
shell option were enabled. The = operator is equivalent to ==. If
the shell option nocasematch is enabled, the match is performed
without regard to the case of alphabetic characters. The return
value is 0 if the string matches (==) or does not match (!=) the
pattern, and 1 otherwise. Any part of the pattern may be quoted to
force the quoted portion to be matched as a string.
An additional binary operator, =~, is available, with the same
precedence as == and !=. When it is used, the string to the right
of the operator is considered an extended regular expression and
matched accordingly (as in regex(3)). The return value is 0 if the
string matches the pattern, and 1 otherwise. If the regular
expression is syntactically incorrect, the conditional expression's
return value is 2.
+
and-
?"