You got many problems, as the special characters will be evaluated mulitple times in your case.
First in the set
command, the special character phase will reduce your string "^^!^^^&^^^^"
to
^!^&^^
But as delayed expansion is enabled and your string contains an exclamation mark,
another phase will be enabled to reduce the carets again to.
!&^
At this point param1
contains !&^
, you can test it with set param1
But as you try to echo the value with echo %param1%
another expansion will be executed.
And now you get a problem, as %param1%
will expand to !&^
,
The exclamation mark will be removed, as the second exlamation mark is missing for expanding a variable,
the ampersand will be treated as new command separator and
the ending caret will be treated as multiline character.
echo ! & ^<next line>
It's much safer to use the delayed expansion here, as this never change the content, as this phase is the last one of the parser.
setlocal EnableDelayedExpansion
set param1=%~1
set param1
echo !param1!
And all these explanations can be found at How does CMD.EXE parse scripts?