1

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.

2
  • How are you getting list_of_combinations? Commented Oct 20, 2013 at 16:12
  • Your second loop with ./program $COMBO INPUT >> OUTPUT should work as long as the arguments cannot themselves contain spaces. Commented Oct 21, 2013 at 12:55

2 Answers 2

2

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.

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

1 Comment

When @Pgibas said that it should work like ./program 1 2 3 INPUT >> OUTPUT, I assumed he meant that those commands actually worked when typed literally. :\
1

By putting the options on the command line:

./program $COMBO INPUT >> OUTPUT

So your second example should work. What goes wrong with it?

2 Comments

I already tried that (check my question). This would work it there was only one character as variable.
As I said above, what goes wrong? What do you mean "This would work it there was only one character as variable"?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.