DOS bat file to add to path

This may not be the right place, since it is not exactly unix or linux, but it does involve cygwin. I have two cygwin installations. When I start a mintty terminal, I need to toggle a windows path variable to make sure that the correct cygwin dll gets loaded.

I need to add

C:\cygwin\bin

to the windows path for one of the installs. I can make a bat file with,

SET PATH = C:\cygwin\bin;%PATH%;

as far as I know, this will add the right string to the path. The issue is that I need this to be temporary for the session only. I am not sure how to do this. I may be able to use "setlocal", but when the bat file finishes, it will close and I'm guessing that the temp assignment to the path will go with it. This means that I would need to have the bat file stay open until I close it intentionally when I am done. It would be more useful to have the path addition stay put until I close the mintty terminal, but I'm not sure how to do that. I suppose I could have a bat file that would add cygwin to the path and then another one that would remove it, but it seems like there should be a better way than that. I guess I could also just open a cmd terminal and add cygwin to the path there and remove it when I was done.

I would like to just have a desktop shortcut that would add cygwin to the path, open a mintty terminal, and then when I am done, restore the path to it's original value. It doesn't seem as if that should be that difficult, but I'm not making much progress with google.

Let me know if this just isn't the right place and I will look elsewhere.

LMHmedchem

You could have the batch file run the terminal, inherit those environment changes.

Thanks for the reply.

This seems to work,

@echo off
SET PATH = C:\cygwin\bin;%PATH%;
start "" /b C:\cygwin\bin\mintty.exe -i /Cygwin-Terminal.ico -

Apparently the /b flag opens the program in the same console. I guess that means that mintty inherits the change. If I run this bat and enter "echo $PATH" in the terminal I get,

/usr/local/bin:/usr/bin:/cygdrive/c/Program Files/Intel/iCLS Client:/cygdrive/c/WINDOWS/system32:/cygdrive/c/WINDOWS:/cygdrive/c/WINDOWS/System32/Wbem:/cygdrive/c/Program Files/Intel/Intel(R) Management Engine Components/DAL:/cygdrive/c/Program Files/Intel/Intel(R) Management Engine Components/IPT:/cygdrive/c/Program Files/Emergent 5.3.9 (32-bit)/bin:/usr/lib/lapack

It appears as if the cygwin directories are in the path ( /usr/local/bin:/usr/bin: ). I have no real way of knowing if the is the correct /usr/local/bin since cygwin has truncated the path names.

The problem is that if I start a terminal from the normal shortcut (not using the bat file above) I get the same information when I echo $PATH. I also don't know if I need to start every terminal and every program from such a bat file.

I think it might make more sense to have the cygwin1 install location always be in the path as an environment variable since that is the one I use most often. If I need the cygwin2 install, I would need to run a bat file that would remove the cygwin1 install location from that path and then insert the cygwin2 install location for that session only.

Does that make sense???

LMHmedchem

As it is: no. Unix shells work like that, but DOS doesn't. In fact, when you set a variable in a DOS batch file its value stays until you start the COMMAND.COM (or whatever replacement you use) anew. This is the reason why you can set the PATH variable in AUTOEXEC.BAT and have that change be persistent.

I hope this helps.

bakunin