Remove quotes from named environment variables in Windows scripts
This is not a limitation of the environment variable, but rather the command shell.
Enclose the entire assignment in quotes:
set "myvar=http://example.com?foo=1&bar="
Though if you try to echo this, it will complain as the shell will see a break in there.
You can echo it by enclosing the var name in quotes:
echo "%myvar%"
Or better, just use the set command to view the contents:
set myvar
While there are several good answers already, another way to remove quotes is to use a simple subroutine:
:unquote set %1=%~2 goto :EOF
Here's a complete usage example:
@echo offsetlocal ENABLEDELAYEDEXPANSION ENABLEEXTENSIONSset words="Two words"call :unquote words %words%echo %words%set quoted="Now is the time"call :unquote unquoted %quoted%echo %unquoted%set word=NoQuoteTestcall :unquote word %word%echo %word%goto :EOF:unquote set %1=%~2 goto :EOF