我有一个如下所示的 shell 脚本
。它的工作原理是如果 $table
包含 test
然后执行 small.sh
,elde big.sh
.
if [[ "$table" =~ "test" ]]
then
echo "events"
else
echo "history"
fi
现在我想在 if [[ "$table"=~ “测试”]]
。
我该怎么做
我试过如下
if [[ "$table" =~ "test" && "$table" =~ "success" ]];
then
echo "events"
else
echo "history"
fi
但是当我传递表名 abc1_success
时,它正在打印 history
而不是 events
。
我做错了什么
最佳答案
abc1_success
不包含test
、_test_and_results
和success
。
它只包含成功
。
听起来你想要“或”而不是“和”:
table="abc1_success"
if [[ "$table" =~ "test" || "$table" =~ "success" ]];
then
echo "events"
else
echo "history"
fi
关于linux - 多个字符串到一个字符串比较bash,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48532650/