shell script test command confusion
我很难理解shell脚本中的
从这段代码中:
1 2 3 4 5 6  | if [ !"$n_trig" -a"$i_trig" ] then usage echo"Required options -n and -i are not present" exit 1 fi  | 
我希望在if语句中执行命令列表,因为
下面是
1 2 3 4 5  | + n_trig=false + i_trig=false + p_trig=false + getopts n:i:p: opt + '[' '!' false -a false ']'  | 
1  | if ! ["$n_trig" -a"$i_trig" ]  | 
或者可以在
1  | if [ ! \("$n_trig" -a"$i_trig" \) ]  | 
另外,
1  | if ! ["$n_trig" != true -a"$i_trig" != true ]  | 
看看这个:如何在shell脚本中声明和使用布尔变量?
shell脚本中的布尔值不是超级可靠的,因为不同shell之间存在很多差异。
那就是说你的测试是不正确的,因为!仅适用于第一个值
1 2 3 4 5 6 7  | #!/bin/bash if [ true !="$n_trig" ] && [ true != "$i_trig" ] then usage echo"Required options -n and -i are not present" exit 1 fi  |