=〜"&的含义QUOT;运营商的shell脚本 [英] Meaning of "=~" operator in shell script
问题描述
我碰到一个shell脚本,其中code是
I came across a shell script where the code is
for line in $LIST_ARRAY;do
if [[ $LIST_ARRAY =~ $line ]]
then
echo "true"
....
...
.
什么是在这种情况下使用 =〜
的?
推荐答案
这是平等代字号经营者,允许在if语句中使用正则表达式。
it's the Equal Tilde operator that allows the use of regex in an if statement.
这是附加的二进制运算符,=〜,是可用的,具有相同的
precedence如==和!=。当它被使用时,该字符串的右
运营商被认为是一个扩展的正前pression和匹配
相应地(如在正则表达式(3))。返回值是0,如果字符串
模式匹配,否则为1。如果经常EX pression是
语法不正确,有条件的前pression的返回值是
2.如果shell选项nocasematch使能,而不考虑字母的情况下进行比赛。的任何部分
模式可以被引用,强制其进行匹配的字符串。
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. If the shell option nocasematch is enabled, the match is performed without regard to the case of alphabetic characters. Any part of the pattern may be quoted to force it to be matched as a string.
http://linux.die.net/man/1/bash
这篇关于=〜"&的含义QUOT;运营商的shell脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!