Record the output of the batch gpg --search-keys
commands into variables. For example, get the public key ids or those with *.amazon.com
email addresses:
pubkeyids=$(gpg --batch --keyserver hkp://keyserver.ubuntu.com --search-keys amazon.com 2>&1 | grep -Po '\d+\s*bit\s*\S+\s*key\s*[^,]+' | cut -d' ' -f5)
We can automate searching for keys and adding them to the keyring using bash
parsing that output. As an illustration, I created the following GitHub gist to host the code below.