=~どういう意味ですか? [コピー]

=~どういう意味ですか? [コピー]

条件文に「=~」を含むシェルスクリプトを見つけ、それが何を意味するのか知りたかったです。 Google または SO サイトには運がありません。

例:

if [[ $VAR =~ 'this string' ]]

ベストアンサー1

正規表現一致演算子です。

bashマニュアルページから:

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.

詳しくは、(検索)のマンbashページをご覧ください。=~

おすすめ記事