I am trying to write a shell script where there needs to be a try/except loop. How do I do a loop like this in shell?
What I am trying to do is basically this:
password="user's password here"
Try_command_here:
echo $password | sudo -S apt-get -y purge some-package-here
Except_command_here:
Re-obtain_user_password
After it reobtains the password it would loop so that it can retry. It would do this 3 times, if needed, and if the correct password has not been provided by then it throws up an error window and exits.
I know in Python the command for this is simply try:
and then except:
Is this so for shell or is it something different?
Thanks!!
EDIT
I am targeting the bash shell.
Output of echo $SHELL
===> /bin/bash