0

I would like to execute many jobs by one script in bash. I did two and I cannot execute more. I did it one by one. The following procedure is: ./script /directory fileX. When in the directory are files which script is using to calculate the compatibility of values from fileX.

e.g. ./script ./directory file1& and then as a second ./script ./directory file1 &

I would like to do from file 1 to e.g file 10.

Is it possible to do it? If yes, please help.

2

This can be done via for loop for example

for i in $(seq 1 10)
do
./script ./directory file$i &
done
0

Bash3+ with brace expansion.

for i in {1..10}; do
  /script ./directory "file$i" &
done

With POSIX sh

i=1
while [ "$i" -le 10 ]; do
  /script ./directory "file$i" &
i=$((i + 1))
done
4
  • you should start with i=1 and while check should be -le 10. otherwise you will do it till 9. Or you can change the places of /script..... and i=$((..... lines Feb 19 '20 at 20:05
  • @RomeoNinov, thank you for that wonderful comment, but if you start counting from zero until nine you still manage to run the code 10 times right?
    – Jetchisel
    Feb 19 '20 at 20:11
  • 1
    But the OP want from 1, not 10 times :) Feb 19 '20 at 20:29
  • 1
    @RomeoNinov, right How did I missed that ... :-(, updated the answer.
    – Jetchisel
    Feb 19 '20 at 23:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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