【发布时间】:2015-12-07 18:43:52
【问题描述】:
我想比较两个字符串,然后再比较另外两个字符串。 所以如果 $version 不等于 5 并且 type 不等于 dbma 或者如果 $version 不等于 6 并且 $type 不等于 dbmy
我的语法不太正确。
if [[ "${version}" != "5" ]] && [[ "${type}" != "dbma" ]] || [[ "${version}" != "6" ]] && [[ "${type}" != "dbmy" ]]
then
xyz
else
abc
fi
有人可以帮忙吗?
【问题讨论】:
-
你的问题和你的代码一样模棱两可。 shell 会从左到右解析这个,所以你可以有效地 if ((version is not 5 and type is not "dbma") or version is not 6) and type is not "dbmy" ...但你应该在你的问题来说明你的意思。我猜你实际上想要 (foo and bar) 或 (baz and quux)?