I am trying to do this in a DOS CMD Script:
@setlocal
@for /L %%X in (1,1,10) do @call :label1 %%X
@endlocal
@exit /b
:label1
@set I=%1
@set /P A%I%=SET A%I% to?
@echo You entered %%A%%I%%
exit /b
However I cannot get it to echo the actual entered value. I have tried all variations on the echo line.
Can anyone tell me what I am doing wrong?
To get your output, you could use
call echo You entered %%A%I%%%.But it would be better to use delayed expansion so that special characters like & and | can never cause you problems:
echo You entered !A%I%!In order to use delayed expansion, you need to enable it with
setlocal enableDelayedExpansion.Helpful hint 1 – Put
@echo offat the top of your script. Then you never need to use@in any of the following commands.Helpful hint 2 – You should explicitly clear any existing variable value prior to using SET /P. You can’t be sure it is not already defined. If the user simply presses
<Enter>without entering anything, then the existing value will be preserved.Helpful hint 3 – You don’t even need the
Ivariable. You can simply use the%1parameter wherever you have%I%.Helpful hint 4 – Better yet, you don’t even need to call a subroutine.