testing - BASH test exist directory with a variable as path -
i simple test know if directory exist in bash script.
directory path in variable.
test works path of file not work variable.
# if [ -d $test ]; echo ok; fi # >> ### no output ### # if [ -d ~/dir/ ]; echo ok; fi # >> ok # echo $test # >> ~/dir/
i define variable mysef :
# test="~/dir/"
i don't understand why not work variable whereas contains same path.
thanks
your test doesn't work variable because contains tilde (~
).
you can use eval
recommended approach use ${home}
instead of ~
in variable. try:
test="${home}/dir" [[ -d $test ]] && echo ok
Comments
Post a Comment