I need a system variable and assign an empty string value to it. I've tried
setx samplepassword ""
But upon echo %samplepassword%
, what should be an empty string is instead %samplepassword%
. Now I found this in the docs
Setting value of "" (empty quotes) will appear to delete the variable - it's not shown by SET but the variable name will remain in the registry.
How can I assign an empty system variable using setx?
Update:
I have checked the environment variables via the Windows GUI: Control Panel | System | Advanced | Environment Variables
and saw that the DB_PASSWORD
was indeed initialized with an empty string value. But why does executing echo %samplepassword%
give me the above output? I have opened a new instance of cmd to be precise.
I think you have a misconception here. There is no way to assign an "empty string" to an environment (Batch) variable. The command set "samplepassword=" deletes the variable, so echo "%samplepassword%" just show "". You don't need setx command to do that, nor setx can modify this behavior. – Aacini Aug 9 at 4:39
TL;DR: Technically it is not possible to create an empty variable in the environment. – Aacini