Running a shell script through Cygwin on Windows
Solution 1:
Sure. On my (pretty vanilla) Cygwin setup, bash
is in c:\cygwin\bin
so I can run a bash
script (say testit.sh
) from a Windows batch file using a command like:
C:\cygwin\bin\bash testit.sh
... which can be included in a .bat
file as easily as it can be typed at the command line, and with the same effect.
Solution 2:
One more thing - if You edited the shell script in some Windows text editor, which produces the \r\n
line-endings, cygwin's bash wouldn't accept those \r
. Just run dos2unix testit.sh
before executing the script:
C:\cygwin\bin\dos2unix testit.sh
C:\cygwin\bin\bash testit.sh
Solution 3:
If you have access to the Notepad++ editor on Windows there is a feature that allows you to easily get around this problem:
- Open the file that's giving the error in Notepad++.
- Go under the "Edit" Menu and choose "EOL Conversion"
- There is an option there for "UNIX/OSX Format." Choose that option.
- Re-save the file.
I did this and it solved my problems.
Hope this helps!
Read more at http://danieladeniji.wordpress.com/2013/03/07/microsoft-windows-cygwin-error-r-command-not-found/
Solution 4:
Just wanted to add that you can do this to apply dos2unix fix for all files under a directory, as it saved me heaps of time when we had to 'fix' a bunch of our scripts.
find . -type f -exec dos2unix.exe {} \;
I'd do it as a comment to Roman's answer, but I don't have access to commenting yet.