1

I have a loop that is doing a GPG verification, serially. When it gets to a failure however, it exits the loop. How can I program this loop so that it does not?

Currently I have:

while read -r line;
gpg --verify $line
do 
  if gpg --verify $line; then
   echo "success";
  else 
   echo "failed gpg check";
  fi
done < gpg_verify.txt

I want the failure to be acknowledged but I don't want it to stop.

sWarren
  • 473
  • 2
  • 4
  • 10
  • Maybe this SO question will help. [Bash ignoring error for a particular command](https://stackoverflow.com/questions/11231937/bash-ignoring-error-for-a-particular-command) – Abra Feb 17 '20 at 20:00
  • 1
    which of the two `gpg` calls is failing? what happens if you remove the `gpg --verify $line` that's between the 'while` and `do` clauses? – markp-fuso Feb 17 '20 at 20:01

1 Answers1

2

Don't use the verification to decide when to exit the loop. Also, fix your quoting.

while read -r line
do 
  if gpg --verify "$line"; then
   echo "success";
  else 
   echo "failed gpg check";
  fi
done < gpg_verify.txt

Just to spell this out, while x; y stops whenever y fails, and won't stop when x fails. Perhaps you meant while x && y but here, just put y inside the loop if that's what you actually want.

tripleee
  • 175,061
  • 34
  • 275
  • 318