Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

shell - Bash regex =~ operator

What is the operator =~ called? Is it only used to compare the right side against the left side?

Why are double square brackets required when running a test?

ie. [[ $phrase =~ $keyword ]]

Thank you

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
  1. What is the operator =~ called?

    I'm not sure it has a name. The bash documentation just calls it the =~ operator.

  2. Is it only used to compare the right side against the left side?

    The right side is considered an extended regular expression. If the left side matches, the operator returns 0, and 1 otherwise.

  3. Why are double square brackets required when running a test?

    Because =~ is an operator of the [[ expression ]] compound command.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...