I have a text file in which I save all my important personal data like all my accounts' passwords and my credit cards' PINs in case I forget those. Obviously, that file needs to be encrypted, so I resorted to gpg (GNU Privacy Guard).
The problem is, every once in a while I must reopen the file not only for reading, like recovering a password I did forgot, but for writing too, like writing down the password for a new account I made on a new site. Then, I need to delete the old archive, create a new archive from the updated text file, and delete the text file.
I made a simple script to do all this in just an action, but I just found a major flaw today: if I fail to enter a new password (like entering a different string when it asks you to repeat your choice), the archive will obviously not be created, as gpg will give an error message, but the script will go further, deleting your new text file, when it already had deleted the old archive as first action.
The script is in fact as follows:
gpg -c $1
How can I avoid this, entering a control cycle that counts the gpg error message, recognizing when something went wrong and the new archive wasn't created?
I know that I can just remove the first line, but I'd want to avoid answering 'yes' to the overwriting message each time, as I know the archive already exists. Also, I'd want to keep the updated text file instead of the old archive if some error occurs, as I don't want to modify the file another time again repeating the edit (I might have forgotten it in the meantime anyway).