4

echo %PATH% will print the enviroment variable PATH. But I want to assign the environment variable to a batch variable first and then get the value of the environment variable. Is it possible?

Something as follows:

set myvar=PATH
echo %myvar%

The above code will echo "PATH". But I want to get the enviroment variable PATH

1 Answer 1

11

try with :

set myvar=PATH

call echo %%myvar%%

or with delayed expansion (it should work faster):

@echo off
set myvar=PATH
setlocal enableDelayedExpansion
echo !%myvar%!

Why you can use directly set set "myvar=%PATH%" ?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.