Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

batch - echo all variables set IN the batch file

Let's suppose that I have this code:

@echo off
set "var=value"
echo %var%

Now my question is: how to echo all variables set in the file?

I know you can do:

set

And it will display all variables. It displays:

ALLUSERSPROFILE=C:\ProgramData
APPDATA=C:\Users\foma\AppData\Roaming
CommonProgramFiles=C:\Program Files\Common Files
CommonProgramFiles(x86)=C:\Program Files (x86)\Common Files
CommonProgramW6432=C:\Program Files\Common Files
...

I want that it displays:

var=value

I know I can do set var to display all variables starting with var, but in my case all my variables are "imported" from another batch file, so I don't know how the variable name starts. Any ideas?

like image 268
HackR_360 Avatar asked May 03 '26 01:05

HackR_360


1 Answers

@echo off
setlocal
set>originalfile.txt
...
:: list environment changes
set|findstr /x /L /g:originalfile.txt

Should work - snapshot the starting values, then the findstr line should show you all changes made (except deletions) - at least in theory, this is just an on-the-fly suggestion.

like image 135
Magoo Avatar answered May 05 '26 09:05

Magoo