在bash中,我们希望执行以下逻辑:如果变量"$SLACK"
为TRUE
且${OUTPUT}
不等于"mysql: [Warning] Using a password on the command line interface can be insecure"
,请调用{{1功能。
我已尝试过How do I negate a test with regular expressions in a bash script?,Check if a string matches a regex in Bash script中的帖子提供的十几个解决方案,但这些解决方案都不起作用。任何古茹都可以开导吗?
slack_it
答案 0 :(得分:3)
星星需要在引号之外。
此外,=~
运算符用于正则表达式,==
用于globs。
所以:
if ! [[ ${OUTPUT} == *"mysql: [Warning] Using a password on the command line interface can be insecure"* ]]; then
slack_it
fi
答案 1 :(得分:1)
您的问题似乎与前导*
有关。尝试:
if ! [[ ${OUTPUT} =~ "mysql: [Warning] Using a password on the command line interface can be insecure" ]]; then
slack_it
fi