Reputation: 6391
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/
Upvotes: 20
Views: 45426
Reputation: 671
mkdir ${CLIENT_BUILD_DIR}
will do. No directory will be created if it already exists.
Upvotes: 1
Reputation: 13651
The ~
character is not reinterpret when used in a variable.
You can use CLIENT_BUILD_DIR="$HOME/Desktop/TempDir/"
instead.
Upvotes: 16
Reputation: 16917
The quotes prevent the expansion of ~.
Use:
CLIENT_BUILD_DIR=~/Desktop/TempDir/
if [ ! -d "$CLIENT_BUILD_DIR" ]
then mkdir "$CLIENT_BUILD_DIR"
fi
Upvotes: 30