if [ -z "$1" ] ; then
# find all secret keys
- keyID=$(gpg --with-colons --list-secret-keys | grep ^sec | cut -f5 -d:)
+ keyID=$(gpg --with-colons --list-secret-keys | grep ^sec | cut -f5 -d: | sort -u)
# if multiple sec keys exist, fail
if (( $(echo "$keyID" | wc -l) > 1 )) ; then
echo "Multiple secret keys found:"
# fail if multiple sec lines are returned, which means the id
# given is not unique
- if [ $(echo "$gpgOut" | grep '^sec:' | wc -l) -gt '1' ] ; then
+ if [ $(echo "$gpgOut" | grep -c '^sec:') -gt '1' ] ; then
failure "Key ID '$keyID' is not unique."
fi