Under some circumstances, the gpg front-ends exit with exit code 2 even
when a decryption is actually successful. This happens with gpg 1.4.1
(from the debian package version 1.4.1-1.sarge7), if use-agent is set in
~/.gnupg/options but gpg cannot connect to agent. It then falls back to
reading the pass-phrase from the terminal and even
if the decryption is successful then, gpg exits with exit code 2:
$ gpg --decrypt file
You need a pass-phrase to unlock the secret key for
user: "Bernhard Herzog <email@example.com>"
1024-bit ELG-E key, ID 2F11C50C, created 2001-01-02 (main key ID 9F884AC8)
gpg: can't connect to `/tmp/gpg-q0/S.gpg-agent': No such file or directory
gpg: encrypted with 1024-bit ELG-E key, ID 2F11C50C, created 2001-01-02
"Bernhard Herzog <firstname.lastname@example.org>"
.... <decrypted content> ...
$ echo $?
With gpg2 and gpgsm version 2.0.3 the fallback is different, but they
still exit with code 2 if the initial attempt to connect to the agent
I would expect gpg, gpg2 and gpgsm to exit with code 0 if the operation
is successful, even though falling back to a different way to get the
pass-phrase was necessary.