# 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? • If @WillW answered your question, please mark it as accepted! :) – Swivel Jun 4 at 14:42 ## 1 Answer I think you need to wrap$var in quotes.

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