Looping over read in bash until correct input is given

Viewed 2461

Hello I was wondering what would be the proper way to pass command as variable into prompt? For example, I have:

#!/bin/bash
clear ;
i=`ifconfig tap0 | awk '{print $2}' | egrep "([0-9]{1,3}[\.]){3}[0-9]{1,3}"`

read -p "Enter your IP: " prompt
        if [[ $prompt == i ]]
    then
        echo "Correct IP, congrats"
    else 
read -p "Wrong IP, try again: " prompt
        if [[ $prompt == i ]]
    then
        echo "Correct IP, congrats"
    else
        echo "Wrong IP for the second time, exiting."
    exit 0
fi

I am sure this can be looped, but I don't know how,. I am starting with bash scripting, So I am learning the dirty way :) Thank you

1 Answers
Related