I'm back here for another question, this time about macros.
I'd want to call a multi-line macro by using !..! (if possible) in order to use dynamic macro names like in the following call for a single-line macro:
setlocal disabledelayedexpansion
:: Simple single-line macros for testing purpose.
set "_testA=echo A" & set "_testB=echo B"
setlocal enabledelayedexpansion
:: Choose macro _testA or _testB.
set /p char="Type A or B:"
:: Execute the chosen macro.
!_test%char%!
endlocal
endlocal
For example,
setlocal disabledelayedexpansion
:: Line feed character.
(set CHR10=^
%=Do not remove this line, or you will be turned into a frog=%
)
:: End of line in a macro code.
set ^"\nmac=^^^%CHR10%%CHR10%^%CHR10%%CHR10%^^"
:: Simple multi-line macro for testing purpose, it could be replace with one receiving parameters obviously.
set _test=(echo A%\nmac%
echo B%\nmac%
echo C)
setlocal enabledelayedexpansion
:: Works as expected, displays A then B then C.
%_test%
:: Doesn't work... as expected also, displays `(echo Is Not Recognized as an Internal or External Command, Operable Program or Batch File.`
!_test!
endlocal
endlocal
The problem seems to comes from the definition of CHR10 when using with !..! (using %_test% works, obviously).
Any idea to solve this ? A solution could help me to refactor some code.
Thanks in advance for your answer.