简体   繁体   中英

command line argument to a batch file

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM