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

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

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

10条回答
  •  暖寄归人
    2020-12-02 05:05

    In Bash at least the following command tests if $var is empty:

    if [[ -z "$var" ]]; then
       # Do what you want
    fi
    

    The command man test is your friend.

提交回复
热议问题