A few weeks ago I tried converting a Windows batch script to a Linux shell (bash) script. The syntax between windows and linux shell scripts is quite different, but I also had a problem other than syntax differences.
After modifying the script to use linux syntax (e.g. proper loops instead of labels and GOTOs), I ran the script but it returned the following message:
/bin/bash^M: bad interpreter: No such file or directory
A quick google revealed the problem was the file using windows line endings (\r\n), while linux uses \n for line endings. Luckily there is a handy utility found in most linux distros that you can use to convert files containing windows line endings to linux line endings.
In Ubuntu I used
fromdos, though other distros might use
dos2unix. In terminal just type
If you want to convert a file from linux to windows line endings instead, you can just use