Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I copy the value of an environment variable into another environment variable? I'm updating a DOS batch script for use on Windows XP. Let's say that I have environment variable FOO, which contains some\file\path, and I need to make an exact copy of this file in environment variable BAR. How is that accomplished?

Variable FOO is setup as such:

setx FOO %MY_ROOT%\some\file\path

How do I make BAR equal FOO by only referencing FOO?

share|improve this question
up vote 2 down vote accepted

Setx BAR %FOO%

You have to be careful with SETX though, as it doesn't apply the variables set to the current CMD window.

So you'd have to open a CMD, run Setx FOO path, exit the current CMD window and/or open a new one, at which point %FOO% will take effect, and you can then assign FOO to BAR with Setx BAR %FOO%.

You can use Set to assign variables that work immediately in the current CMD session, but Set's scope is only within the current CMD session, so you may need to use a combination of both.

share|improve this answer
    
The equal sign (=) causes an error. – Jim Fell Jan 30 '12 at 17:58
    
Thanks for the help! – Jim Fell Jan 30 '12 at 17:59
    
Yeah, I realized I had erroneously stuck those in there (that's Set's syntax), so I edited them out. :) – Ƭᴇcʜιᴇ007 Jan 30 '12 at 17:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .