I have a bunch of shell scripts that used to run on a Linux machine. Now, we\'ve switched over to Windows, and I need to run these scripts there. I have Cygwin installed, bu
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.
The existing answers all seem to run this script in a DOS console window.
This may be acceptable, but for example means that colour codes (changing text colour) don't work but instead get printed out as they are:
there is no item "[032mGroovy[0m"
I found this solution some time ago, so I'm not sure whether mintty.exe
is a standard Cygwin utility or whether you have to run the setup
program to get it, but I run like this:
D:\apps\cygwin64\bin\mintty.exe -i /Cygwin-Terminal.ico bash.exe .\myShellScript.sh
... this causes the script to run in a Cygwin BASH console instead of a Windows DOS console.
If you have access to the Notepad++ editor on Windows there is a feature that allows you to easily get around this problem:
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/
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.
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
If you don't mind always including .sh on the script file name, then you can keep the same script for Cygwin and Unix (Macbook).
To illustrate:
1. Always include .sh to your script file name, e.g., test1.sh
2. test1.sh looks like the following as an example:
3. On Windows with Cygwin, you type "test1.sh" to run#!/bin/bash
echo '$0 = ' $0
echo '$1 = ' $1
filepath=$1
4. On a Unix, you also type "test1.sh" to run
Note: On Windows, you need to use the file explorer to do following once:
1. Open the file explorer
2. Right-click on a file with .sh extension, like test1.sh
3. Open with... -> Select sh.exe
After this, your Windows 10 remembers to execute all .sh files with sh.exe.
Note: Using this method, you do not need to prepend your script file name with bash to run