in a.bat
if ... set a.b=1
...
set c=%%~!a.b!
echo %c% prints %~1
, but I need contents of %~1.
but set c=%~!a.b!
results in "The following usage of the path operator in batch-parameter substitution is invalid: %~!a.b!." How to fix?
in a.bat
if ... set a.b=1
...
set c=%%~!a.b!
echo %c% prints %~1
, but I need contents of %~1.
but set c=%~!a.b!
results in "The following usage of the path operator in batch-parameter substitution is invalid: %~!a.b!." How to fix?
You can't access the parameters with an evaluated expression directly,
as the percent expansion is one of the first phases of the parser.
But the CALL-trick can help you here.
Something like
set paramNo=1
call echo %%~%paramNo%
will expands first to
call echo %%~1
and the CALL
will restart the parser, so you get your desired result.