I need to run a cygwin shell script without changing the working directory, from outside the cygwin environment.

If I run just \path\to\bash.exe -c command, then the path is not set correctly and cygwin programs can't be found.

If I use the --login option, bash sets the path correctly, but also changes to my home directory.

What options should I use to launch bash to keep the current working directory, and also find cygwin executables?


It turns out that the cygwin default /etc/profile checks for an environment variable named CHERE_INVOKING and inhibits the change of directory if set.


\path\to\bash.exe -l -c command

has the desired behavior.

  • This works for invoking MSYS2 bash as well. – tharen Jan 9 '15 at 8:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.