decrypt multiple OpenPGP files in a directory

gpg can decrypt multiple files so you shouldn't need to write a loop.

Try the following. You will need to enter your password once.

gpg --passphrase-fd 0 --decrypt-files *.gpg 

I had success with

gpg --decrypt-files *.gpg

cf. https://serverfault.com/a/388068/103585


As it is said in the manual you need to add --batch option:

   --passphrase-fd n
          Read the passphrase from file descriptor n. Only the first line will be read from file descriptor n. If you use 0 for n, the passphrase will be read from
          STDIN. This can only be used if only one passphrase is supplied.  Note that this passphrase is only used if the option --batch has also been given.  This is
          different from gpg.

   --passphrase string
          Use string as the passphrase. This can only be used if only one passphrase is supplied. Obviously, this is of very questionable security on a multi-user sys‐
          tem. Don't use this option if you can avoid it.  Note that this passphrase is only used if the option --batch has also been given.  This is different from
          gpg.

You can have either of these two forms:

echo "passphrase" | gpg --passphrase-fd 0 --batch -d --output "decrypted.file" "file.gpg"

Or simpler:

gpg --passphrase "passphrase" --batch -d --output "decrypted.file" "file.gpg"

You can try a script like this to extract your files:

#!/bin/bash

read -rsp "Enter passphrase: " PASSPHRASE

for FILE in *.*.gpg; do
    echo "Extracting $FILE to ${FILE%.gpg}."
    echo "$PASSPHRASE" | gpg --passphrase-fd 0 --batch -d --output "${FILE%.gpg}" "$FILE"
done