Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I write quoted Environment Variables to a file using cmd?

Tags:

cmd

I can't figure out how to write "%PROGRAMFILES%" literally to a file using Windows Command Prompt.

What I've tried:

C:\Users\lxvs> echo "%PROGRAMFILES%" > test
C:\Users\lxvs> type test
"C:\Program Files"

C:\Users\lxvs> echo ^%PROGRAMFILES^% > test
C:\Users\lxvs> type test
%PROGRAMFILES%

C:\Users\lxvs> echo "^%PROGRAMFILES^%" > test
C:\Users\lxvs> type test
"^%PROGRAMFILES^%"

C:\Users\lxvs> echo "%%PROGRAMFILES%%" > test
C:\Users\lxvs> type test
"%C:\Program Files%"

Is there a way to approach it?

like image 390
lxvs Avatar asked May 04 '21 07:05

lxvs


1 Answers

Escape the quotes, so that the carets inside get parsed and removed.

C:\etc>echo ^"%^ProgramFiles%^" >test

C:\etc>type test
"%ProgramFiles%"

C:\etc>
like image 182
dxiv Avatar answered Sep 23 '22 13:09

dxiv