How do you check if a variable is null in Unix?

Đức Linh

New member
How do you check if a variable is null in Unix?
Answer
To find out if a bash variable is null:
  1. Return true if a bash variable is unset or set to the null (empty) string: if [ -z “$var” ]; then echo “NULL”; else echo “Not NULL”; fi.
  2. Another option to find if bash variable set to NULL: [ -z “$var” ] && echo “NULL”
  3. Determine if a bash variable is NULL: [[ !
27 дек. 2018 г.
 

Tìm kiếm

Back
Top