mercredi 21 mars 2018

Why does my batch file echo the array name and number instead of the string?

I have this code here simply trying to create a file that the name is chosen from a randomized array. Why does it output incorrectly?

Code:

@echo off

set i=0
for %%a in (Cow Dog Bird Fish Meerkat Cat) do (
   set /A i+=1
   set operator[!i!]=%%a
)
set /a operator=%random%%%4+1
set operator=!operator[%operator%]!

copy /y NUL %operator%>NUL

The file created is titled something like !operator[3]! instead of one of the strings in the array. Why is this the case? Any help is appreciated!




Aucun commentaire:

Enregistrer un commentaire