Script error: "syntax error near unexpected token 'then'"
Hi all, very new at this and completely stumped as to what's gone wrong here. I'm trying to get this script working, it's supposed to give me options of typing B to backup a folder, typing R to restore the backup, and typing E to exit.
Code:
#!/bin/sh Code:
line 18: syntax error near unexpected token 'then' |
It's not on line 18 in the posted script but the then on tar zc /home/Rory/backups -f /home/Rory/archive/Rory-`date+%d%m%y`.tar.gz; then is not right.
EDIT: and if [ “entry” == “backup” ]; shuold be if [ “$entry” == “backup” ]; |
Quote:
Here's a simple example of how to code a conditional in bash: http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-6.html |
Look at line 18?
Code:
tar zc /home/Rory/backups -f /home/Rory/archive/Rory-`date+%d%m%y`.tar.gz; then |
Thanks for the replies guys - I removed all the "then"s and added the $ where required, but although that particular error is gone, I'm now getting the same error again but for "fi" instead of "then". And yet again, I'm completely lost. ><
|
As the link I gave demonstrates, the syntax of a bash conditional statement is as follows:
Code:
if [ test ]; then Code:
fi [ test ]; then If you need more specific assistance, please post the updated version of your script. |
Still pretty lost >< This is how my code looks right now:
Code:
#!/bin/sh |
This is a corrected version of your script (please check the differences):
Code:
#!/bin/sh |
Thanks for the corrections colucix - the old errors are now gone, but I'm now getting a new one:
Code:
line 45: unexpected EOF while looking for matching " |
I cannot see any non-matching " in the script above. Can you post the updated version of your script?
|
I'm using the corrected version of the script that you have already posted, I've checked it over several times and mine is definately the same.
|
This is line 45 in the corrected script:
Code:
echo "Invalid entry. Please type B, R or E." Again... post what you have. |
Alright, but it's exactly the same as a few posts above:
Code:
#!/bin/sh |
Indeed it looks right. Every double quote pair is perfectly matched. I really don't know what happens. :confused:
|
What about executing the script with debugging on, i.e.
Code:
#!/bin/sh -x |
All times are GMT -5. The time now is 12:05 PM. |