【发布时间】:2017-09-21 18:34:45
【问题描述】:
在bash中,我们想做如下逻辑:如果变量"$SLACK"是TRUE并且${OUTPUT}不等于"mysql: [Warning] Using a password on the command line interface can be insecure",调用slack_it函数。
我已经尝试了How do I negate a test with regular expressions in a bash script?、Check if a string matches a regex in Bash script 此处的帖子提供的十几种解决方案,但没有一个有效。有哪位大师能开导吗?
#!/bin/bash
if [ "$SLACK" == "TRUE" ]
then
if ! [[ ${OUTPUT} =~ "*mysql: [Warning] Using a password on the command line interface can be insecure*" ]]
then
slack_it
fi
fi
【问题讨论】:
-
我很好奇你为什么要使用正则表达式。听起来你让它在没有正则表达式的情况下工作。为什么要把事情复杂化?还是这是一种思维练习?
标签: regex bash if-statement