Parallelize a loop in bash

I have the following snippet in a bash script

#!/bin/bash
    for ((i=100; i>=70; i--))
      do
        convert test.png -quality "$i" -sampling-factor 1x1 test_libjpeg_q"$i".jpg
      done

How can I execute a for loop in parallel using all cpu cores. I saw gnu parallel, but here I need the name of the output file in a specific naming scheme, as shown above.

+4
source share
1 answer

You can use parallelas follows:

parallel \
'convert test.png -quality {} -sampling-factor 1x1 test_libjpeg_q{}.jpg' ::: {100..70}
+6
source

Source: https://habr.com/ru/post/1684621/


All Articles