Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex “的含义=~&引用;shell脚本中的运算符_Regex_Linux_Bash_Shell - Fatal编程技术网

Regex “的含义=~&引用;shell脚本中的运算符

Regex “的含义=~&引用;shell脚本中的运算符,regex,linux,bash,shell,Regex,Linux,Bash,Shell,我遇到了一个shell脚本,其中的代码是 for line in $LIST_ARRAY;do if [[ $LIST_ARRAY =~ $line ]] then echo "true" .... ... . 在这种情况下,=~的用法是什么?在if语句中,允许使用regex的是相等的Tilde运算符 另外还有一个二进制运算符=~,具有相同的 优先级为==和!=。当它被使用时,右边的字符串 该运算符被视为扩展正则表达式并匹配 因此(如regex(3))中所述)。如果字符串为0,则返回值为0 与

我遇到了一个shell脚本,其中的代码是

for line in $LIST_ARRAY;do
if [[ $LIST_ARRAY =~ $line ]]
then
echo "true"
....
...
.

在这种情况下,
=~
的用法是什么?

在if语句中,允许使用regex的是相等的Tilde运算符

另外还有一个二进制运算符=~,具有相同的 优先级为==和!=。当它被使用时,右边的字符串 该运算符被视为扩展正则表达式并匹配 因此(如regex(3))中所述)。如果字符串为0,则返回值为0 与模式匹配,否则为1。如果正则表达式是 语法不正确,条件表达式的返回值为 2.如果启用了shell选项nocasematch,则执行匹配时不考虑字母字符的大小写。任何部分 模式可以被引用,以强制它作为字符串进行匹配


对于循环,您应该真正命名循环变量
word
,而不是
line