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

Use*_*345 1 linux bash

我有一个shell script喜欢下面。它的工作条件是 if $tablecontains testthen small.shexecutes , elde big.sh

if [[ "$table" =~ "test" ]]
then 
  echo "events"
else
  echo "history"
fi
Run Code Online (Sandbox Code Playgroud)

现在我想检查表是否包含test,_test_and_resultssuccessin if [[ "$table" =~ "test" ]]

我怎样才能做到这一点

我试过如下

if [[ "$table" =~ "test" && "$table" =~ "success" ]];
then
    echo "events"
else
    echo "history"
fi
Run Code Online (Sandbox Code Playgroud)

但是当我传递表名时,abc1_success它正在打印history而不是events.

我在这里做错了什么

tha*_*guy 6

abc1_success不包含test,_test_and_resultssuccess

它只包含success.

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

table="abc1_success"
if [[ "$table" =~ "test" || "$table" =~ "success" ]];
then
    echo "events"
else
    echo "history"
fi
Run Code Online (Sandbox Code Playgroud)