小编Zai*_*ida的帖子

将布尔比较的值分配给变量

我有一个脚本,需要在字符串变量的内容之间进行所有可能的比较。每种组合都需要对变量的内容采用不同的方法,因此如下所示:

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)

scripting bash shell-script

7
推荐指数
2
解决办法
2138
查看次数

标签 统计

bash ×1

scripting ×1

shell-script ×1