我有一个脚本,需要在字符串变量的内容之间进行所有可能的比较。每种组合都需要对变量的内容采用不同的方法,因此如下所示:
if $a contains "a" AND "b" AND "c"; then do x
elif $a contains "a" AND "b" but NOT "c"; then do y
elif $a contains "b" AND "c" but NOT "a"; then do z
...
Run Code Online (Sandbox Code Playgroud)
据我所知,这样做的方法是构造一个像这样的 if 条件:
if [[ $A == *"b"* ]] && [[ $A == *"c"* ]] && [[ $A == *"d"* ]]
elif [[ $A == *"b"* ]] && [[ $A == *"c"* ]]
elif [[ $A == *"c"* ]] && [[ $A == …Run Code Online (Sandbox Code Playgroud)