Code: Select all
@echo off&goto :start
:Assign.bat "EnVar=String with quotes & Poison chars to assign to variable EnVar"
echo(
echo(USAGE: %~nx0 "Envar=String which may contain 'Poison' characters"
echo(
echo(Format: Must place quotes at the very beginning and end of argument string
echo( as in the USAGE example to assign difficult strings to a variable.
echo(
echo(To display the variable use delayed expansion, ie. Echo ^^!Envar^^!
echo( or use Set/p with quotes, ie. ^<nul Set/p="%%EnVar%%"
echo(
echo(If double quotes are used inside the string they must be 'balanced' with a
echo(second double quote inside the string and unwanted results may occur
echo(if poison characters are quoted inside the string.
goto :eof
:start
setlocal enableDelayedExpansion
if !"%~1" equ ""! goto :Assign.bat
if !"%~1" equ "/?"! goto :Assign.bat
>"%temp%\getArg.txt" <"%temp%\getArg.txt" (
setlocal disableExtensions
set prompt=#
echo on
for %%a in (%%a) do rem . %*.
echo off
endlocal
set /p "args="
set /p "args="
set "args=!args:~7,-2!"
)
endlocal& set %args%&exit /b