Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass a list of strings to a batch-script as a parameter?

Tags:

batch-file

My batch script is used to process a list of strings and I would like to parameterize it so it will accept this list as a parameter from the user.

This is how my code is processing this list currently:

set QUEUES=cars plans others
FOR %%q IN (%QUEUES%) DO Call :defineQueues %%q

How should I pass this list to the QUEUES varibale as a parameter?

For example, how should I pass it to this script:

myScript.bat ?
like image 943
Yair Nevet Avatar asked Mar 02 '15 12:03

Yair Nevet


1 Answers

You have to enclose your string with quotes:

myScript.bat "cars plans others"

Then %1 will be equals to "cars plans others"

Or %~1% to remove the quotes and only get cars plans others

Otherwise, you will get 3 different parameter values:

myScript.bat cars plans others

%1 => cars
%2 => plans
%3 => others
like image 199
Fionnuala Avatar answered Oct 26 '22 10:10

Fionnuala