Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shell variable issue when trying to mkdir

Any ideas what is wrong with this code?

CLIENT_BUILD_DIR="~/Desktop/TempDir/"

if [ ! -d $CLIENT_BUILD_DIR ]
then
   {
      mkdir $CLIENT_BUILD_DIR
   }
fi

I get the error: mkdir: ~/Desktop: No such file or directory.

Obviously the directory is there and the script works if I replace the variable with ~/Desktop/TempDir/

like image 294
hax0r_n_code Avatar asked Apr 18 '13 14:04

hax0r_n_code


1 Answers

The quotes prevent the expansion of ~.

Use:

CLIENT_BUILD_DIR=~/Desktop/TempDir/

if [ ! -d "$CLIENT_BUILD_DIR" ]
then mkdir "$CLIENT_BUILD_DIR"
fi
like image 89
BeniBela Avatar answered Oct 14 '22 18:10

BeniBela