This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Run bash script in cmd with cygwin


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]