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.

What I have to do currently:

cd C:\Program Files (x86)\MyProgram\modules\bin

What I'd like to do:

set dir as %Path%
cd %Path%

Is there a quick way to do this from command prompt? Also, would I be able to call these path variables from Linux based bash shells like the git bash shell or cygwin? Thanks in advanced!

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

That's not really how the path variable works.

If you add a directory to the path variable, you don't have to change to the directory to execute a program.

For example,

C:\>set Path=C:\Program Files (x86)\MyProgram\modules\bin;%Path%
C:\>program

will execute C:\Program Files (x86)\MyProgram\modules\bin\program.exe.

If you just want to store a directory's name in a variable (which shouldn't be Path), you can do this:

C:\>set myBin="C:\Program Files (x86)\MyProgram\modules\bin"
C:\>cd %myBin%
C:\Program Files (x86)\MyProgram\modules\bin>

If you want to set an environment variable for all command prompts (without having to enter set...), you can do so in

Computer [right click] -> Properties -> Advanced System Settings -> Environment Variables
share|improve this answer
    
I didn't realize the path variable had it's own specific use. I was just using it as a placeholder like %myVariable%. But The information is good to know despite. The second answer is what I was looking for, Thanks! –  mcmullins Dec 17 '11 at 20:26
add comment

In Command Prompt (cmd.exe), you can set environment variables using set:

set var=value
set "var=value"

and access them using %var%:

cd "%var%"

They will also be put into the environment of that cmd.exe process, and inherited by all processes you run from it. If you run bash inside this cmd window, it will have the same variable as $var. If you run python, it will have os.environ['var'], and so on.

However, environment variables can be only inherited. If you change a variable in cmd or bash, it will not update the environment of all other running processes, or those you start from Explorer, or those you start from Start menu.

The only exception to the above limitation is when the program can be told to re-read environment from another source; for example, if you use the environment configuration UI at Control Panel → System → Advanced System Settings → Advanced → Environment Variables, Explorer will re-read the environment from registry.

Finally, remember that %PATH% is a special variable, holding the locations of commands you execute. Don't set it to just anything; use %mydir% or whatever else instead.

share|improve this answer
add comment

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.