Bash patterns I use #3: run something in variations.

Bash patterns I use #3: run something in variations.

This is part three of the "Bash patterns" series. The second part covers argument parsing.

True story: my CMO asks me to run this benchmark. But, this time it is not a one-off. Instead, we need permutations on compression methods and levels.

I typically make a small Bash script for things like this to save time and effort. The script for this task is right below (run_benchmark is a function defined elsewhere):

COMBINATIONS=("zstd,1" "zstd,5" "zstd,9" "lz4,1" "lz4,5" "lz4,9")
for combination in "${COMBINATIONS[@]}"; do
    IFS="," read -r CTYPE CLEVEL <<<"$combination"
    run_benchmark $CTYPE $CLEVEL
done

Straightforward and effective. Now, you can do something more important than waiting for each run to be done to kick-off the next one.

Notes

  • Photo by Iva Muškić from Pexels