I’m trying to output the contents of an array index # by referencing the index # using the A1.length value. But since I still don’t fully understand the expansion of variables, the most I get for output is either the actual length value or the string A1.length.
Now, I can get it to work if I create/set a work variable to reference A1.length, like so, but is this required:
set temp=!%~1.length!
echo !%~1[%temp%]!
This outputs the actual content/value of each index in the array named A1, and works for what I need it to do. But is a worker variable actually required to do this?
Here are a few things I have tried:
echo !%~1[%~1.length]!
output> ECHO is off.
echo %~1[!%~1.length!]
output> A1[1]
call echo %~1[%%%~1.length%%]
output> A1[1]
echo !%~1[!%~1.length!]!
output> A1.length
What am I missing or forgetting?
This should help clarify if there is any confusion:
Basically, it just comes down to using the correct variable expansion symbols to echo the value of the Array index, which in my case is Array=A1, Index=length (let’s say length=1) and Value=Superuser. Using any of the example statements I provided above, why can’t I get the value Superuser to echo?