2

I am trying to run a program that uses two different files:

Program -command1 $file1 -command2 $file2

i have used the bash loop for one file successfully but when i use it as:

for file in *.ext
do
    Program -command1 $file -command2 $file
done

It runs the same one file for both commands, looping to second file and doing the same thing for that one.

what i need the program to run both files individually for each command under one program run.

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
knav
  • 21
  • 1

1 Answers1

0

Dummy code, using printf to output three directory names, and use xargs to feed those names to Program, (actually to echo so the results are visible):

printf '%s\n' foo bar baz | 
xargs -I '{}' echo Program -command1 '{}'/Type1.ext -command2 '{}'/Type2.ext

Output:

Program -command1 foo/Type1.ext -command2 foo/Type2.ext
Program -command1 bar/Type1.ext -command2 bar/Type2.ext
Program -command1 baz/Type1.ext -command2 baz/Type2.ext

To actually run Program, replace "foo bar baz with the names of the actual directories, and omit the echo:

printf '%s\n' ....dir names go here... | 
xargs -I '{}' Program -command1 '{}'/Type1.ext -command2 '{}'/Type2.ext
agc
  • 7,973
  • 2
  • 29
  • 50