1.

Solve : Adding a counter to FOR loop?

Answer»

I am TRYING to make a script to update a mac address for a device, i used the following

SET /A n=1
FOR /F "delims=" %%G in (mac.txt) do (
set /A n=n+1
Echo the value of n is: %n%
plink.exe -ssh [emailprotected] -pw password ethtool -E eth0 offset %n% value 0x%%G
)


this FOR loop run for 6 times to taking the value of TH emac address from a file mac.txt and put it in the Plink command, this is working fine.

My problem is i cannot figure out how to change the value of n to increment from 1 to 6, the value of n is always set to one, during running this script only the first byte of the mac address change 6 times because n value stay 1.

Another question, is there a way to put the mac address in the FOR loop instead of taking it from the text file?

Thanks,You need to use delayed expansion and the !VARIABLE! syntax instead of %variable%Thanks for the quick respond, but I am not sure what do you mean?
I am new in Patch file and do not know what "Delay Expansion" mean?Code: [Select]setlocal enabledelayedexpansion
set /A n=1
FOR /F "delims=" %%G in (mac.txt) do (
set /A n=n+1
Echo the value of n is: !n!
plink.exe -ssh [emailprotected] -pw password ethtool -E eth0 offset !n! value 0x%%G
)It work the way I want.
This is a new piece of information fro me.

Thank you.



Discussion

No Comment Found