0

I have a problem with my loop, i don't know how to use the %%A to edit my variable.

For example, i want to set IPAdresse like that:

  • 10.98.1.10
  • 10.98.2.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.

2
  • 5
    Very poor description of your problem , but looks like you need delayed expansion - ss64.com/nt/delayedexpansion.html Commented Jan 29, 2018 at 9:43
  • I just edit my message. Commented Jan 29, 2018 at 9:51

2 Answers 2

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

Is the generic way of doing this.

Sign up to request clarification or add additional context in comments.

Comments

1

You should use 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

1 Comment

Put an Exit/b after the pause and not at the end :PingIP

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.