Empty variables in termux' bash

by Josef Klimuk   Last Updated November 14, 2017 15:11 PM

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? enter image description here

Tags : bash termux

Answers 1

I think you need to wrap $var in quotes.

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

November 14, 2017 14:56 PM

Related Questions

Variables in 'if' tests in bash

Updated November 07, 2017 07:11 AM

Use GCC compiler in Termux?

Updated August 27, 2017 11:11 AM

Path for bash in Android termux

Updated November 01, 2017 10:11 AM

Is there /etc/shadows in android termux?

Updated November 02, 2017 12:11 PM