Forum Moderators: bakedjake

Message Too Old, No Replies

Syntax Error?

         

sbaci

7:18 pm on May 14, 2003 (gmt 0)

10+ Year Member



Im new to this and i was trying to create a script that
allows a user to backup a directory and all the files and directories below it. I was trying to get the program to take exactly two parameters, the name of a source directory (to back up) and a destination directory (to back up to). If the user does not enter exactly two parameters, I wanted the program to output a suitable error messages and exit.

Thought i had it done and dusted but when i run it the following error message appears

syntax error at line 33: `end of file' unexpected" and i havnt a clue how to fix it, and get my script working, any help please?

#!/bin/sh #Path of the shell transient command

if [ "$1 $2" -ne "0" ]; then echo "Sorry, you must enter two parameters exactly"
exit 1
else
if [! -f $1 ]
then
echo "The directory [$1] does not exist - Aborting"
exit
else
'cp -R $1 $2' #Backs up the directories mentioned in the command line
fi
if [ -f $2 ]
then
echo "The directory [$2] already exists"
/usr/5bin/echo "Do you want to overwrite the directory? ( y/n ) :\c"
read answer
read $answer
echo ""
if [ "Łanswer"!= "y" ] && [ "$answer"!= "Y" ]
then
echo "Aborting"
exit
fi
fi
fi

sbaci

7:31 pm on May 12, 2003 (gmt 0)

10+ Year Member



sorry i meant the following line is causing the error

shellscript4.sh: syntax error at line 3: `then' unexpected

marcs

5:23 am on May 13, 2003 (gmt 0)

10+ Year Member



if [ "$1 $2" -ne "0" ]; then echo "Sorry, you must enter two parameters exactly"

Remove the ';' and put the then on the next line (the latter being cosmetic). See if that fixes it.