Hans Yulian
Hans Yulian

Reputation: 1180

How do i put a %variable% name in bat / cmd file

For example if we create a .bat file contains:

echo "%PATH%"

We will get our PATH variable content shown in our command prompt. So now i want to make a simple script to make this environment variable on my windows and when i execute this script:

echo %TESTING%

i will see this:

%some_other_variable%

but, apparently %some_other_variable% is executed as if it's a environment variable when we double click the .bat file. Is there any way to prevent the execution of looking for variable name in bat/cmd file? currently my script is as follow:

setx testing '%development_dir%'

and the result i expect is the in my environment variable, i have a key testing with value %development_dir%, not some real path such as C:\development or anything, still keeping them as %development_dir%.

if it need to change the whole script, it's fine, as long as it's able to be double clicked and make my life easier.

Upvotes: 0

Views: 3043

Answers (1)

Joey
Joey

Reputation: 354576

Double the % signs:

setx testing "%%development_dir%%"

Upvotes: 3

Related Questions