Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question
    
Hi, similar question was being discussed at StackOverflow: stackoverflow.com/questions/9637601/… –  Roman Hocke Jan 16 at 11:15
    
@Roman: This would be totally off-topic on SO. –  Ben Voigt Jan 16 at 12:47

1 Answer 1

up vote 6 down vote accepted

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.

So

set CHERE_INVOKING=1
\path\to\bash.exe -l -c command

has the desired behavior.

share|improve this answer
2  
Its CHERE_INVOKING in the version of cygwin I'm using. –  P.T. Apr 16 '12 at 22:08
    
@P.T.: So it is. I'll update my answer. –  Ben Voigt Apr 16 '12 at 23:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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