Remove quotes from named environment variables in Windows scripts
echo %myvar:"=%
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 off
setlocal ENABLEDELAYEDEXPANSION ENABLEEXTENSIONS
set words="Two words"
call :unquote words %words%
echo %words%
set quoted="Now is the time"
call :unquote unquoted %quoted%
echo %unquoted%
set word=NoQuoteTest
call :unquote word %word%
echo %word%
goto :EOF
:unquote
set %1=%~2
goto :EOF
This works
for %a in (%myvar%) do set myvar=%~a
I would also use this if I wanted to print a variable that contained and ampersand without the quotes.
for %a in ("fish & chips") do echo %~a