What Does %~1 Do In This Batch Scripting, Windows Batch Scripting

I need to run a windows command n times within a bat script file. I know how to do this in various programming languages but cannot manage to get it right on the windows command line 🙁

I would expect something like either

for(int i = 0; i or even this (though not entirely seriously)

1.upto(100, { // do something}) Thanks!

EDIT

I can write a program in java, perl, c or whatever that will generate a bat script that looks like this

for %%N in (1 2 3 4 5 6 7 8 9 10 11 12) do echo %%Nand so on. Or even “better”:

echo 1echo 2echo 3echo 4echo 5echo 6echo 7echo 8echo 9echo 10echo 11echo 12and then execute it… But the thing is that I need a concise way to specify a range of numbers to iterate through within the script.

Thanks!

Đang xem: Batch

windows batch scripting
Share
Improve this question
Follow
edited Aug 26 “09 at 14:44
raoulsson
asked Aug 26 “09 at 14:09

*

raoulssonraoulsson
4,3331010 gold badges3030 silver badges2929 bronze badges
7
| Show 2 more comments

3 Answers 3

Active Oldest Votes
50
You can do it similarly like this:

ECHO Start of LoopFOR /L %i IN (1,1,5) DO ( ECHO %i)The 1,1,5 is decoded as:

(start,step,end)Also note, if you are embedding this in a batch file, you will need to use the double percent sign (%%) to prefix your variables, otherwise the command interpreter will try to evaluate the variable %i prior to running the loop.

Share
Improve this answer
Follow
edited Nov 6 “14 at 11:05

*

Winter
10366 bronze badges
answered Aug 26 “09 at 14:21

*

GoyuixGoyuix
3,00444 gold badges2626 silver badges3636 bronze badges
5
Add a comment |
9
Syntax is

FOR %%A IN (1 2 3) DO ECHO %%AGood article here and XP specifics here

Share
Improve this answer
Follow
edited Aug 26 “09 at 14:19
answered Aug 26 “09 at 14:14

*

AndyAndy
5,1402121 silver badges3333 bronze badges
1
Add a comment |
8

Xem thêm: Vay Tiền Nhanh Kon Tum – Vay Tiền Online Nhanh Trong 30 Phút

Directly from the command line:

for /L %n in (1,1,100) do
echo %nUsing a batch file:

echo offfor /L %%n in (1,1,100) do echo %%nDisplays:

123…100
Share
Improve this answer
Follow
edited Sep 23 “12 at 0:41

*

jscott
23.3k88 gold badges7070 silver badges9696 bronze badges
answered Sep 10 “12 at 14:50
fmoraesjrfmoraesjr
8111 silver badge22 bronze badges
1
Add a comment |
Highly active question. Earn 10 reputation in order to answer this question. The reputation requirement helps protect this question from spam and non-answer activity.

Not the answer you're looking for? Browse other questions tagged windows batch scripting or ask your own question.

The Overflow Blog
Featured on Meta
Related
1
Need to exclude a specific result from a Batch For Loop
6
Evaluating expressions in windows batch script
517
How do I tell Git for Windows where to find my private RSA key?
2
Dos Batch File Help: Storing %%c variable from FOR loop
0
How to prevent schtasks on Windows 7 from showing the command prompt after executing a task?
2
Weird issue with .bat script
1
Loop in a Windows batch file
Hot Network Questions more hot questions
Question feed
Subscribe to RSS
Question feed To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

Server Fault
Company
Stack Exchange Network
site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev2021.4.6.38996

Xem thêm: Pin On Kmsauto Net 2020 – The Kms Auto Net Activator 2021 Official™

Server Fault works best with JavaScript enabled

*

Your privacy

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Leave a comment

Your email address will not be published. Required fields are marked *