Writing Bash scripts on windows

When writing Bash scripts for cygwin on windows, most text editing software will add a DOS carriage return which when the bash script is run in cygwin will cause it to fail.

There seems to be two solutions

  1. Use dos2unix or similar to convert the .sh file to a proper unix version
  2. Use the following line of code at the top of your .sh file
(set -o igncr) 2>/dev/null && set -o igncr;

Useful ink: http://stackoverflow.com/questions/11616835/cygwin-r-command-not-found-bashrc-bash-profile