In batch files variables should be referred as %%%%variable
On command lines variables should be referred as %%variable
eg. to loop using for
In command line
@FOR /L %%a in (1,1,254) DO @echo 172.31.5.%%a
In batch file
@FOR /L %%%%a in (1,1,254) DO @echo 172.31.5.%%%%a