Reputation: 107
i'm trying write simple IF statement in bash, but no mater what i try i allway get error, that shouldn't rise at all, can someone please take a look at my code and tell me what am I doing wrong?
#!/bin/bash
echo "Checking..."
echo
if [ -f /var/www/git/repos/last_change.txt ];
then
echo "/var/www/git/repos/last_change.txt exists."
cd /var/www &&
git fetch --all &&
git reset --hard origin/develop &&
rm -f "/var/www/git/repos/last_change.txt"
fi;
echo
echo "...done."
I allways get error:
root@machine:/var/www/git/repos# sh check.sh
Checking...
: not found: 3: check.sh: echo
check.sh: 12: check.sh: Syntax error: "fi" unexpected (expecting "then")
Everything seems to be ok, right?
I am glad for any help, thanks.
Upvotes: 0
Views: 54
Reputation: 18399
Judging by error description, most likely your file uses DOS newlines (CRLF). sh
expects UNIX newlines (LF). Convert your file with dos2unix your_file_name.sh
.
Upvotes: 3