Hi folks, i want to understand some differences between Switches and Parameters.
Switch = they ask the program or script to disable/enable something; on or off; yes/no. (e.g.: 'dir /AD' or 'dir /A-D')
Parameter = provide some information to the program or script. (e.g.: 'dir C:\Temp')
Arguments = the program or script takes an Switch or an Paramter as Argument to controll what it should do and how.
- switch is a special kind of an parameter.
- parameter are what I call an application with to act as I want.
- arguments are what an application use to know what to do for me, provided by me as parameter.
I found one site that explains Parameters:Command line parameters
Batch files can only handle parameters %0 to %9
%0 is the program name as it was called,
%1 is the first command line parameter,
%2 is the second command line parameter,
and so on till %9.
What do i understand about %0, and %1 till %9. How does it can be applied in batch file.
Any suggestion from experts would be greatful.
Batch file "Test1.cmd"@ECHO OFF
ECHO Hello %1
Call as: test1 hulkbuster has a question
Call as: test1 "hulkbuster has a question"
Hello "hulkbuster has a question"
Batch file "Test2.cmd"@ECHO OFF
ECHO Hello %~1
Call as: test2 "hulkbuster has a question"
Hello hulkbuster has a question
- - -
Batch file "ParameterPresenter2.cmd"@ECHO OFF
Call as: ParameterPresenter "Hi folks," i want to "understand some" differences.
- - -
If I want to provide a Switch to my batch, like "Test3.cmd /?",
I would have to parse the arguments for '/?' and in case I found it,
switch in my code to the corresponding place:
Pseudo demo code
For ARG in AllArgs
If ARG == "/?" Then GoTo _displayHelpMessage()