2

I have a shell script that will ask for username and it will check against a list. if the name is inside the list, it will run another shell script but if the name cannot be found, it will prompt a error message and exit the shell script.

But i would like to allow 3 retries before exiting the shell script.

Below is my shell script

#!/bin/bash

name=$(whiptail --title "Title" \
--backtitle "Backtitle" \
--inputbox "Enter your User ID" 0 40 3>&1 1>&2 2>&3)

if [[ -z $name ]]
then
    whiptail --title "Error" --msgbox "Please enter User ID to proceed" 10 50
    . ./start.sh
else
    egrep  -i "\<$name\>" ./user.list
    case $? in
        0)
        . ./main_menu.sh
        ;;
        1)
        whiptail --title "Error" --msgbox "Program terminated. You are not authorised to use this program" 10 50    
        ;;
        esac
fi

1 Answer 1

6
i=0
while [ $i -le 3 ]; do

code && break

let i=i+1
done

See this answer for further details.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .