New Location

My website has moved to http://www.jasonwhaley.com. Please visit there for the latest and only remain here for legacy content.

Wednesday, December 16, 2009

Running bash scripts and commands from bash.

In short, use the following: C:\cygwin\bin\bash.exe --login -i -c 'your normal bash stuff here'

Basically, this starts a bash shell and the arguments to bash do the following:
  • --login and -i makes the current shell process act as if it has been invoked as an interactie login shell, which takes of reading and executing /etc/profile and your ~/.bash_rc and ~/.bash_profile fiiles.
  • -c basically takes the string you give the -c argument and runs that, making your bash shell exist only until that shell's completion.

Combined, it's a perfect way to run anything from bash through windows - which may be needed for such things as Scheduled Tasks or to incorporate bash and unix goodies in existing batch files.