The Blacklist - follow-up Follow-up from this question using @Toby Speight's answer:

The primary concern is jq improvement/optimization, but please detail any others.
#!/bin/sh

set -eu

sources=$(mktemp)
trap 'rm &quot;$sources&quot;' EXIT

curl -s -o &quot;$sources&quot; https://raw.githubusercontent.com/T145/packages/master/net/adblock/files/adblock.sources

for key in $(jq -r 'keys[]' &quot;$sources&quot;)
do
    case $key in
        gaming | oisd_basic )
        # Ignore these lists
        ;;
        * )
            url=$(jq -r &quot;.$key.url&quot; &quot;$sources&quot;)
            rule=$(jq -r &quot;.$key.rule&quot; &quot;$sources&quot;)

            curl -s &quot;$url&quot; |
                case $url in
                    *.tar.gz) tar -xOzf - ;;
                    *) cat ;;
                esac |
                gawk --sandbox -- &quot;$rule&quot;
    esac
done |
    sed -e 's/\r//g' -e 's/^/0.0.0.0 /' | sort -u &gt; the_blacklist.txt
# use sort over gawk to merge sort multiple temp files instead of using up limited memory
Don't use a for loop to iterate over program output. See http://mywiki.wooledge.org/BashFAQ/001
Try this -- extract the keys, urls, rules all at once:
jq -r 'keys[] as $k | [$k, .[$k].url, .[$k].rule] | @tsv' &quot;$sources&quot; |
while IFS=$'\t' read key url rule; do 
    case $key in 
       ...

If, for some reason, your shell does not understand $'\t', use
while IFS=&quot;$(printf '\t')&quot; read ...