Reputation: 28379
My program takes three options ./program a b c INPUT > OUTPUT
(a
,b
,c
are options).
I have a list of option combinations:
cat list_of_combinations
1 2 3
4 8 3
1 5 7
9 5 6
I want to execute program
using those four different combinations. For example:
./program 1 2 3 INPUT >> OUTPUT
./program 4 8 3 INPUT >> OUTPUT
./program 1 5 7 INPUT >> OUTPUT
I already tried this:
while read COMBO; do
echo $COMBO |
./program - INPUT >> OUTPUT
done < list_of_combinations
And this:
while read COMBO; do
./program $COMBO INPUT >> OUTPUT
done < list_of_combinations
My question is:
How to execute program/command while using a string of variables as options?
Edit
I wouldn't have any problems if there was only one character as variable. What I mean by that:
Program takes only one option:
./program a INPUT > OUTPUT
cat VARIABLES
1
15
78
while read VARIABLE; do
./program $VARIABLE INPUT > OUTPUT
done < VARIABLES
But when there are several options (string of characters), for example ./program a b INPUT > OUTPUT
I am getting error.
Upvotes: 1
Views: 206
Reputation: 786349
Use quotes around your argument variable:
while read COMBO; do
./program "$COMBO" INPUT >> OUTPUT
done < list_of_combinations
Without quotes $COMBO
will be considered 3 different inputs rather one single string as with the quotes.
Upvotes: 2
Reputation: 95395
By putting the options on the command line:
./program $COMBO INPUT >> OUTPUT
So your second example should work. What goes wrong with it?
Upvotes: 1