1

run multiple values from a file on a single command one after another

I have a the following command

    ./test.sh -f test.txt

     Completed Success

I have 1000 of inputs to be passed to the same script which I have in a file example.txt.

every time the script executes and output successful.

cat example.txt

test.txt
test1.txt
test2.txt
test3.txt

etc

I want the command to fetch each and every line and execute in a batch process like

./test.sh -f test.txt
  Completed Success
./test.sh -f test1.txt
  Completed Success
./test.sh -f test2.txt
  Completed Success

and so on.

2 Answers 2

1

Use for or while loop:

for i in `cat example.txt`; do ./test.sh -f $i;done

Or

while read i; do ./test.sh -f $i;done < example.txt
1
< example.txt xargs -n 1 -t ./test.sh -f
3
  • it breaks after the first execution
    – Danny
    Commented Feb 20, 2017 at 23:13
  • 1
    what is the error ? Commented Feb 20, 2017 at 23:20
  • instead of < use cat and pipe . cat example.txt | xargs -n 1 -t ./test.sh -f will run through all lines
    – amisax
    Commented Feb 21, 2017 at 6:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .