Compare integer in bash, unary operator expected

前端 未结 4 1427
谎友^
谎友^ 2020-12-04 05:44

The following code gives

[: -ge: unary operator expected

when

i=0

if [ $i -ge 2 ]
then
    #some code
fi
         


        
4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-04 06:38

    Your piece of script works just great. Are you sure you are not assigning anything else before the if to "i"?

    A common mistake is also not to leave a space after and before the square brackets.

提交回复
热议问题