How do you set and call a path variable in command prompt?

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 the command prompt? Also, would I be able to call these path variables from Linux-based bash shells like the git bash shell or Cygwin?


Solution 1:

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