Reputation: 187
I'm still learning how to program in bash and for practice i'm trying to do a "backup script" (quotes because I know this isn't a proper backup) here is the code:
#|/bin/bash
sudo mkdir /home/lucas/bkp
echo "Type the path for the directory you want do save"
read directory
if [-d $directory]; then
sudo cp -R $directory /home/lucas/bkp/
else
echo "Path not found"
fi
But I get an error saying the path saved on variable does not exists and doing the same commands by "hand", directly on the shell everything is fine. Here is the error:
lucas@lucas-Linux:~$ sudo sh ./ex.sh
Type the path for the directory you want do save
/home/lucas/git/
./ex.sh: 7: ./ex.sh: [-d: not found
Path not found
Upvotes: 1
Views: 157
Reputation: 192
You need to put spaces in your condition, like this :
if [ -d $directory ]; then
Upvotes: 1