Getting Environment Variable in windows batch file

21,008

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%" ?

Share:
21,008
Stanly
Author by

Stanly

Updated on November 21, 2020

Comments

  • Stanly
    Stanly over 3 years

    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