Run bash script in cmd with cygwin

Warren Young warren@etr-usa.com
Wed Sep 25 14:12:00 GMT 2013


On 9/24/2013 15:43, Ulrich Pogson wrote:
>
> I would like to run this script `for file in `find . -name "*.po"` ;
> do msgfmt -o ${file/.po/.mo} $file ; done` in windows cmd.

What exactly do you mean by "in windows cmd"?

If you're trying to translate this script into cmd.exe's "batch" 
language, it's not going to be an easy translation because batch is 
about as impoverished as programming languages get, and you're using 
some pretty advanced Bash features here.  Pattern substitution in 
variable interpolation and command output substitution don't even exist 
in cmd.exe's batch language.  You'd have to fake it with temporary files 
or some other hack like that.

If you're just trying to get this bit of Bash code to run from cmd.exe 
but you can still have Bash installed, the solution is fairly simple:

     d:\path\to\dir> bash -c "for file in..."

The trickiest part is handling all the quoting, so it gets to bash.exe 
correctly.  It might be simpler to put this into a script file so you 
can say "bash -c /path/to/my/script.sh" instead of depending on cmd.exe 
to get quoting right.

You also have to handle the PATH issues.

The simplest option is to make sure the Cygwin bin directory is at the 
start of the PATH while in cmd.exe.

If you can't do that, then you end up with something fairly ugly:

    c:\> c:\cygwin\bin\bash -c "for file in `/bin/find..."

Note that you have to give explicit path names in both DOS and POSIX 
forms here for the different parts.  You have a special trap here 
because Windows provides a find.exe, and it isn't at all the same thing 
as Cygwin's find.exe.

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple



More information about the Cygwin mailing list