简体   繁体   English

批处理文件-用于循环增量

[英]Batch file - For loop incrementation

I have a problem with my loop, i don't know how to use the %%A to edit my variable. 我的循环有问题,我不知道如何使用%% A来编辑变量。

For example, i want to set IPAdresse like that: 例如,我要像这样设置IPAdresse:

  • 10.98.1.10 10.98.1.10
  • 10.98.2.10 10.98.2.10
  • 10.98.3.10 ... 10.98.3.10 ...

Here the code : 这里的代码:

FOR /L %%A IN (1,1,200) DO (

set "IPAdresse=10.98.%%A.10"

---> do something

)

Thanks in advance. 提前致谢。

FOR /L %%A IN (1,1,200) DO ping 10.98.%%A.10

是执行此操作的通用方法。

You should use SETLOCAL EnableDelayedExpansion 您应该使用SETLOCAL EnableDelayedExpansion

@echo off
SETLOCAL EnableDelayedExpansion
FOR /L %%A IN (1,1,200) DO (
    set "IPAdresse=10.98.%%A.10"
    Call :PingIP !IPAdresse!
)
pause
exit /b
:PingIP 
echo Pinging %1
Ping %1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM