Question: The below program is supposed to read and validate an IP address keyed in by the user. Validations of IP works fine . What I need is figuring out the setup of the condition(while/if&else) that will prompt the user to re-enter IP in case of keying in invalid IP address?

```
        echo "Enter an IP address:"
          read IP_ADDRESS

    # Check if the format looks right 
    if echo "$IP_ADDRESS" | egrep -E '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'
    then

     #check that each octect is less than or equal to 255:
     VALID_IP_ADDRESS="$(echo $IP_ADDRESS | awk -F'.' '$1 <=255 && $2 <= 255 && $3 <= 
     25&&  $4 <= 255')" 

    ## Here is the Pseudo code of  what I am trying to achieve 
    # If the IP address is not VALID_IP_ADDRESS prompt the user to re-enter IP
    #Pseudo Code not actaul
    while [[ ! VALID_IP_ADDRESS]] do 
    read -p "Not an IP. Re-enter: " IP_ADDRESS
     done
     # Another way to I tried 
     if  $VALID_IP_ADDRESS; then

     echo "You have alright IP address!"
     else
    read -p "Not an IP. Re-enter: " IP_ADDRESS
    fi

```

Answer: 
```
is_valid() {
    IP_ADDRESS="$1"
    # Check if the format looks right_ (Added the two extra meta characters for better results)
    echo "$IP_ADDRESS" | egrep -qE '^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$' || return 1
    #check that each octet is less than or equal to 255:
    echo $IP_ADDRESS | awk -F'.' '$1 <=255 && $2 <= 255 && $3 <=255 && $4 <= 255 {print "Y" } ' | grep -q Y || return 1
    return 0
}

read -p "Enter a valid IP: " IP_ADDRESS
while ! is_valid "$IP_ADDRESS"
do
    read -p "Not an IP. Re-enter: " IP_ADDRESS
done
echo "Success.  You entered a valid IP address of $IP_ADDRESS"

```
You're missing a `done` to close `while [[ ! VALID_IP_ADDRESS]] do`. Try adding that and see if your current solution works. You're also not rechecking the re-entered ip in your loop.