-
Batch scripting can do more than static automation β with tools like
SHIFTandSET /P, you can process dynamic input and build interactive scripts.-
The
SHIFTcommand shifts all command-line arguments one position to the left.It enables batch scripts to handle more than
%9arguments β critical for loops and bulk operations.SHIFT [/n]/nβ Optional, specifies the starting argument to shift from (rarely used in practice)
@ECHO OFF :loop IF "%1"=="" GOTO end ECHO Arg: %1 SHIFT GOTO loop :end
showargs.bat one two three four five six seven eight nine ten eleven
β Output:
Arg: one Arg: two ... Arg: eleven@ECHO OFF :process IF "%1"=="" GOTO done ECHO Processing file: %1 :: Place your logic here SHIFT GOTO process :done ECHO All files processed.
-
-
SET /Pallows your batch script to prompt the user for input β like a simple interactive prompt.SET /P variable=Prompt text
@ECHO OFF SET /P name=Enter your name: ECHO Hello, %name%!
Enter your name: Alice Hello, Alice!
@ECHO OFF :ask SET /P age=Enter your age: IF "%age%"=="" ( ECHO Age is required! GOTO ask ) ECHO Your age is: %age%
SET /P pass=Enter password: IF "%pass%"=="secret" ( ECHO Access granted. ) ELSE ( ECHO Access denied. )
You can combine both to create dynamic + interactive scripts:
@ECHO OFF SET /P confirm=Start processing arguments? (Y/N): IF /I NOT "%confirm%"=="Y" EXIT /B :loop IF "%1"=="" GOTO end ECHO Processing %1 SHIFT GOTO loop :end