I have a code like this
#!/bin/bash
DIR=\"test_dir/\";
if [! -d \"$DIR\"]; then
# If it doesn\'t create it
mkdir $DIR
fi
But why
Add some spaces:
if [ ! -d "$DIR" ]; then
# ^ ^
Add space between [ and !. And before ] as well.
#!/bin/bash
DIR="test_dir/";
if [ ! -d "$DIR" ]; then
# If it doesn't create it
mkdir $DIR
fi
It's also a good idea to quote your variable:
mkdir "$DIR"
You could also attempt to simply by saying:
test -d "${dir}" || mkdir "${dir}"
This would create the directory if it doesn't exist.