gpt4 book ai didi

regex - shell脚本中 "=~"运算符的含义

转载 作者:IT老高 更新时间:2023-10-28 12:36:29 25 4
gpt4 key购买 nike

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

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

这种情况下=~有什么用?

最佳答案

这是允许在 if 语句中使用正则表达式的 Equal Tilde 运算符。

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

关于regex - shell脚本中 "=~"运算符的含义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12454731/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com