What Are Arguments?
Batch scripts can receive values directly from the command line. These values are called arguments and they allow you to pass data into the script when you run it.
myscript.bat Hello World
In the script, you access arguments using:
- %1 → first argument
- %2 → second argument
- %3 → third argument
- … and so on
Example: Print Arguments
@echo off
echo First argument: %1
echo Second argument: %2
pause
Passing Multiple Values
Run the script like this:
details.bat Kaloyan 12 Bulgaria
echo Name: %1
echo Age: %2
echo Country: %3
%*
%* means “all arguments at once”.
echo All arguments: %*
SHIFT Command
SHIFT moves all arguments one position left. Useful for processing each argument in a loop.
:loop
if "%1"=="" goto end
echo Processing: %1
shift
goto loop
:end
Check If an Argument Exists
if "%1"=="" (
echo You must enter a name!
exit /b
)
echo Hello, %1!
Using Arguments in Real Scripts
1. Delete a Specific File
del "%1" || echo Failed to delete file!
2. Backup Script
copy "%1" "%1.bak"
3. Logging With a Custom Message
echo [%date% %time%] %1 >> log.txt
Why Arguments Matter?
- Make scripts reusable
- Let users control behavior
- Allow dynamic input
- Perfect for automation
What’s Next?
Next you’ll learn how Python dictionaries work — key/value data storage used everywhere in Python.