Skip to main content

Batch Script For in Command Line Arguments

For in Command Line Arguments

The for instruction can be used to control command line arguments.

example.bat
@echo off 
:Loop

if "%1"=="" goto completed
for %%f in (%1) do echo %%f
shift
goto Loop
:completed

Suppose the above code is stored in a file called example.bat. The above command will produce the following result if the batch file passes command line arguments 1, 2 and 3 as example.bat 1 2 3.

1
2
3