Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Environment Variable in windows batch file

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

like image 363
Stanly Avatar asked Oct 26 '25 16:10

Stanly


1 Answers

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

like image 169
npocmaka Avatar answered Oct 29 '25 05:10

npocmaka



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!