I'm trying to set a variable to a value without expanding that variable. E.g.,
setx var1 "%nested_var%\dir"
The result is that var1 gets assigned the expanded string, while I'd rather it didn't contain expanded variables. I've tried a number of approaches without results.
Note that this is done on the command line, not in a batch file.
If you are running the command from command prompt, then you can use escape character ^, but you have to remove the quotations, otherwise it will include escape character to variable.
The command would be setx var1 ^%nested_var^%\dir
From the batch you leave the quotation marks and you can escape variable expansion by doubling percentage character.
In the batch use setx var1 %%nested_var%%\dir or setx var1 "%%nested_var%%\dir"
Hope this helps
N.B. If one is using setx command from command prompt, the inner environment variables must not be expanded and environment variable has spaces, then use syntax like this:
setx var1 ^"^%nested_var^%\some dir^"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With