Empty variables in termux' bash I want to perform a test: if a certain variable exists, is non-empty, and its value matches an existing directory, then "exists" should be outputted.

I did the following:

$ echo $var

$ if [ -d $var ]; then echo "exists"; fi
exists


I got "exist", although I did not assign any value to $var. Why did this happen, and how do I test this properly?
I think you need to wrap $var in quotes.

if [ -d "$var" ]; then echo "exists"; fi