Bash nonzero test case (-n), [ and [[ are doing different things

后端 未结 2 1707
既然无缘
既然无缘 2021-01-16 18:48

Usually i only use [[ for all kinds of test cases, because it\'s the most advanced way and it\'s more safe to use (Regex, ...). I know that [[ executes different code than [

2条回答
  •  误落风尘
    2021-01-16 19:17

    Quoting. You have to quote variables that you use in [:

    $ VAR=    
    $ [ -n $VAR ]
    $ echo $?
    0
    $ [ -n "$VAR" ]
    $ echo $?
    1
    

提交回复
热议问题