How to find whether or not a variable is empty in Bash

后端 未结 10 1140
深忆病人
深忆病人 2020-12-02 04:17

How can I check if a variable is empty in Bash?

10条回答
  •  孤街浪徒
    2020-12-02 04:57

    Presuming Bash:

    var=""
    
    if [ -n "$var" ]; then
        echo "not empty"
    else
        echo "empty"
    fi
    

提交回复
热议问题