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

How to turn off bluetooth through adb?

Updated February 18, 2016 01:05 AM

Why does my bashscript always evaluates to true

Updated February 18, 2016 06:05 AM