gpt4 book ai didi

linux - 如何检查 shell 脚本中 if 语句中的两种可能性?

转载 作者:太空狗 更新时间:2023-10-29 11:39:43 27 4
gpt4 key购买 nike

我需要检查两个变量,countcount1,是否与 2 相等。

我试过下面的代码,但是没有用:

if [ $count -eq 2 || $count1 -eq 2 ]; then
echo "Condition passsed"
fi

我该如何解决?

最佳答案

这种类型的条件无法识别 ||。您要么需要使用 -o(或),要么使用 [[ 测试:

if [ $count -eq 2 -o $count1 -eq 2 ]; then
echo "Condition passsed"
fi

if [[ $count -eq 2 || $count1 -eq 2 ]]; then
echo "Condition passsed"
fi

关于linux - 如何检查 shell 脚本中 if 语句中的两种可能性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6071472/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com