0

I want to run a script in commandline like below:

xxxx.bat param1=something1 param2=something2 param3=saomething3

I could do that from the following script:

echo off
cls
@echo first,second arguments :: %1 %2
set %1
set %2
@echo a :::: %a% 
@echo b :::: %b%

I run the script on the command line using the following command,

xxx.bat "a=1" "b=2"

My question is, can I pass the argument without the quotations and can I access the parameters by name in the script directly without using the:

set %1
set %2

1 Answer 1

1

You need to set the variables inside the script if you want the script to be able to use them. You can, however, pass only the values into the script like this:

@echo off
cls
set param1=%1
set param2=%2

Also, as long as the argument doesn't have spaces, you don't need quotation marks.

Sign up to request clarification or add additional context in comments.

3 Comments

I want to know whether I can access the parameter without redefine it in the script since I am passing it in the command line argument.
You're passing a string in as an argument that just happens to have an equals sign in it. The script won't know that you want it to be a variable unless you define it as a variable. If you don't want to define it inside the script, you have to set the variables in the command prompt before you run the script. If you do this, the variables will stay until you close the command prompt or change their values.
Not correct - the quotes are always needed because the cmd parser treats = as a token delimiter (equivalent to a space). So xxx.bat A=B is equivalent to xxx.bat A B

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.