Log in

View Full Version : Anyone here good at Bash coding for linux?


FantaSauce
May 2nd, 2013, 06:45 AM
i have been writing this code to create a backup and i just cannot figure out what the problem is with it. Any help would be greatly appreciated!!


if [ $1 -ne ""]
then
source=$1 ; destination=$2
if [ -r $source ]
then
if [ ! -d $destination ]
then
mkdir $destination
fi
cp -r $source $dest
echo "Backup Complete"
else
echo "Source not found or Source is Unreachable"
fi
else
repeat = 1
while [ $repeat -eq 1 ] ; do
echo "You have no entered a reachable or correct directory for an automatic backup"
echo -n " Please enter the source directory you would like to backup:" ; read source
if [ -r source ]
then
echo -n "Please enter the destination that you would like to back up to:" ; read destination
if [ ! -d $destination ]
then
mkdir $destination
fi
cp -r $source $destination
echo "Backup Complete!"
else
echo " Source not found or was unreachable"
fi
echo "Enter 1 to repeat this program or press 2 to exit"
read repeat
done
fi

TheMatrix
May 3rd, 2013, 01:19 AM
Give an example input, and what you expect should happen. The problem probably lies within one of those two.

FantaSauce
May 3rd, 2013, 05:55 AM
I'm sorry i don't quite get what you mean.

Got it all sorted now had a bit of help from a few uni mates!
Thanks for the help still TheMatrix!

Please edit your post if you have something to add, instead of double posting. ~TheMatrix