tags:

views:

15

answers:

2

Hi,

I'm pretty new to bash, but I have the following script that does a simple operation: copying a folder.

In shell, I would type sudo macaco NewFolder and this is the bash script:

#!/bin/bash

wwwPATH="/var/www"
bitMotorVERSION="0.0.0"
targetDir="$wwwPATH/$1"

cp -r /var/fw/bitMotor/$bitMotorVERSION/ $targetDir

This works fine! Now I want the script to output a little status message, and I 'm having problem with conditions. This is what I got so far:

if [ cp -r /var/fw/bitMotor/$bitMotorVERSION/ $targetDir ]
then echo "New Project '$1' Successfully Created!"
else echo "Something wrent wrong"
fi

Shell says: /usr/bin/macaco: line 7: [: too many arguments

What am I doing wrong?

+2  A: 
if cp -r "/var/fw/bitMotor/$bitMotorVERSION/" "$targetDir" ;then
  echo ....
fi
ghostdog74
tx! it did the trick!
fabjoa
+3  A: 

Hello,

you should using the return status like this :

cp -r /var/fw/bitMotor/$bitMotorVERSION/ $targetDir
if [ $? == 0 ]
    then echo "New Project '$1' Successfully Created!"
else
    echo "Something wrent wrong"
fi
Arnaud F.
tx! worked as a charm
fabjoa