Computing.Net > Forums > Programming > Variables in .bat scripting

Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free!

Variables in .bat scripting

Reply to Message Icon

Original Message
Name: satyam
Date: August 25, 2008 at 00:12:39 Pacific
Subject: Variables in .bat scripting
OS: xp
CPU/Ram: amd
Model/Manufacturer: 2003
Comment:

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


Report Offensive Message For Removal


Response Number 1
Name: tonysathre
Date: August 28, 2008 at 20:09:18 Pacific
Reply: (edit)

%%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 Offensive Follow Up For Removal







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home








Do you have your own blog?

Yes
No
I did before
I will soon


View Results

Poll Finishes In 4 Days.
Discuss in The Lounge
Poll History




Data Recovery Software