user2650277
user2650277

Reputation: 6729

Parallelize for loop in bash

I have the following snippet in my 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 the for loop in parallel using all cpu cores.I have seen gnu parallel being used but here i need the output filename in a specific naming scheme as shown above

Upvotes: 4

Views: 450

Answers (1)

anubhava
anubhava

Reputation: 784888

You can use parallel like this:

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

Upvotes: 6

Related Questions