I want to perform a test: if certain variable exists and has a value of directory, then "esists" should be typed. I did the following: $ echo $var
$ if [ -d $var ]; then echo "exists"; fi exists I got "exist", although I did not assign to $var any dir. Why I got "exists"? And how run the test properly?
I think you need to wrap $var in quotes.
if [ -d "$var" ]; then echo "exists"; fi