Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a Python script that is run like this:

scriptname --param_a=123 --param_b=423 --param_c=xyz

The script expects to be passed three parameters

I have a (configuration) text file, that contains the parameters. I want to write a Bash script (my first), that will use the entries in the file to pass the parameters to the script.

For example if the configuration text file contains the following data:

--param_a=123 --param_b=423 --param_c=xyz
--param_a=203 --param_b=343 --param_c=abz
--param_a=976 --param_b=891 --param_c=abc

Then I want to call the script (3 times) once for each line in the config file, and pass the parameters to the script.

Can anyone suggest how to write such a Bash script.

I intend to run the script on an Ubuntu system

share|improve this question

1 Answer 1

up vote 3 down vote accepted
while read -r -a array
do
    scriptname "${array[@]}"
done < configfile

or

while read -r line
do
    scriptname $line
done < configfile

The advantage to the first one is if your config file had commas, for example, between the parameters instead of spaces:

--param_a=123,--param_b=423,--param_c=xyz

you could do:

while IFS=, read -r -a array
share|improve this answer
    
wow - thanks! –  Takashi Dec 6 '10 at 18:18

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.