linux - 多个字符串到一个字符串比较bash

标签 linux bash

我有一个如下所示的 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_resultssuccess

它只包含成功

听起来你想要“或”而不是“和”:

table="abc1_success"
if [[ "$table" =~ "test" || "$table" =~ "success" ]];
then
    echo "events"
else
    echo "history"
fi

关于linux - 多个字符串到一个字符串比较bash,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48532650/

相关文章:

linux - 我在进行 UDP 高速连续数据接收吗?

linux - 在 bash 脚本中转义冒号

linux - bash 脚本中的一个特定命令在由 cron 运行时不起作用,所有其他命令都可以

linux - Until 循环不终止或保持增量变量的值

linux - 创建 Linux Bash 脚本来复制文件并创建目录

bash - 如何打印文件中包含指定字节偏移量的整行?

php - 在 Debian 上更新到 PHP 5.4

python - 如何将python模块复制到python lib目录

regex - 如何匹配两个文件并按列过滤第三个文件的匹配值?

linux - 基本 Linux bash 命令说明 : awk and others