All I am trying is to store a string in an array and then access them using variable as index. I have tried Delayed Expansion, but I don't know what is wrong with code. Please help. The test.cmd file contains
@echo OFF
@set i=1
echo ENTER Your First Name :
setlocal enableDelayedExpansion
set /p input_value[%i%]=%=%
call:print
endlocal
@set i=2
setlocal enableDelayedExpansion
echo ENTER Your Last Name :
set /p input_value[%i%]=%=%
call:print
endlocal
:print
@echo !input_value[%i%]!
GOTO:EOF
Output:
D:\backup_app\bat>test.cmd
ENTER Your First Name :
radhe
radhe
ENTER Your Last Name :
kishan
kishan
!input_value[2]!
The last line in the output is what that is troubling me.
!input_value[2]!? Try removeendlocalabove:printand you will get kishangoto :EOForexit /Bbefore:printlabel because you are "falling" into the:printroutine a third time unintentionally...