Newbie: Setting environment variables from a .bat file

Brian Dessent brian@dessent.net
Fri Aug 18 06:58:00 GMT 2006


Neil Kolban wrote:

> I have some windows BAT files that set some windows CMD environment
> variables.   I am hoping to run a shell under cygwin but when I run the BAT
> files from a shell prompt, the BAT file set variables are not exported to
> the parent shell.   Is there a way that I can have BAT file set variables
> visible in the calling environment?

As cgf said it doesn't work that way, a child cannot affect the
environment of its parent.  But you can work around this in several
ways.  You can execute the .bat file first to set up the environment and
then launch bash from that same session, and it will inherit the
settings since bash will be a child process.  Or you can translate the
.bat file into bourne shell syntax (using e.g. sed/awk if necessary for
automation) and 'source' it from within bash, which will set the current
environment since no child is created when you source a file.

Brian

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



More information about the Cygwin mailing list