I am working on setting up some shell scripts for backups. Everything is ok but I am getting syntax errors when I use if then statements.
Looking at http://ift.tt/2vjCbeK they use a simple if statements which works on the website as it has a try it pop section. When I copy the contents into a file save as .sh and try it on my ubuntu server (16.04.2 x64), I get Syntax error: "fi" unexpected (expecting "then")
The code from the website is below
#!/bin/sh
a=10
b=20
if [ $a == $b ]
then
echo "a is equal to b"
else
echo "a is not equal to b"
fi
To run on terminal I use
sh /path/to/file/script.sh
There are a few questions asked and answered but none of them seem to be the same as my case. Is there something I need to update on the server? If I use bash instead of sh it says unexpected token. Anyone had this issue?
If it may help, when I run in terminal, it does not seem to like empty spaces, full error is below
sh /var/www/check-day.sh
: not foundeck-day.sh: 4: /var/www/check-day.sh:
/var/www/check-day.sh: 10: /var/www/check-day.sh: Syntax error: "fi"
unexpected (expecting "then")
Aucun commentaire:
Enregistrer un commentaire