How to do a logical OR operation in shell scripting

前端 未结 8 2199
小蘑菇
小蘑菇 2020-11-27 08:55

I am trying to do a simple condition check, but it doesn\'t seem to work.

If $# is equal to 0 or is greater than 1 then say he

8条回答
  •  醉梦人生
    2020-11-27 09:54

    This should work:

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

    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))
     ...
    

提交回复
热议问题