且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Shell脚本中执行逻辑OR运算以进行整数比较?

更新时间:2023-01-22 22:30:39

这应该有效:

#!/bin/bash

if [ "$#" -eq 0 ] || [ "$#" -gt 1 ] ; then
    echo "hello"
fi

我不确定在其他shell中这是否不同,但是如果您想使用&lt ;,>,则需要将它们放在双括号内,如下所示:

I'm not sure if this is different in other shells but if you wish to use <, >, you need to put them inside double parenthesis like so:

if (("$#" > 1))
 ...