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

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

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

10条回答
  •  南方客
    南方客 (楼主)
    2020-12-02 04:55

    I have also seen

    if [ "x$variable" = "x" ]; then ...
    

    which is obviously very robust and shell independent.

    Also, there is a difference between "empty" and "unset". See How to tell if a string is not defined in a Bash shell script.

提交回复
热议问题