Articles

Variables in .bat scripting

August 25, 2008 at 00:12:39
Specs: xp, amd

Hi,

I have just started learning batch scripting.., I want to know why we use the below variables

%%a,%%b,%%c,%%d,%%e,%%f,%%i like this we have so many variales..are these variables are used for any specific purpose?

and what are these number variables for %%1 , %%2, %%3 ,%%4 ,%%5 ,%%6,%%7,%%8,%%9


Please let me know why and where are these variables used.

Regards,
Satyam


See More: Variables in .bat scripting

Report •


#1
August 28, 2008 at 20:09:18

%%a, %%b etc are generally used in FOR loops, such as: for %%a in (*.*) do echo %%a

You can use any letter you want, it doesn't matter.

%1, %2 etc are used on the command line to specify optional arguments.

Take for example this script:

@echo off
set filename=%0
set arg1=%1
set arg2=%2
echo %arg1%
echo %arg2%
echo This file is called %filename%

save that as script.bat, then on the command line: script testARG1 testARG2

The following would be echo'd to STDOUT:

testARG1
testARG2
This file is called script.bat

You can get more info on the use of these variables with the following commands:

for /?
set /?


Report •
Related Solutions


Ask Question