Problem scenario
You run a shell or bash script but you receive an error message such as one of the following:
$'\r': command not found
line:55 syntax error: unexpected end of file
Solution
Did you download the file from the internet directly to the Unix system? The root cause could be that there are invisible characters in the file.
If you can copy the content of the text into the Linux machine and have it run as a script, the invisible characters are to blame. The integration between Windows and Linux can have hitches.
To eliminate these extra characters which interfere with the Bash script's execution, run the following (but substitute "script.sh" with the name of your script):
perl -p -i -e "s/\r//g" script.sh