I
I
Igor Petrov2020-12-09 13:09:23
linux
Igor Petrov, 2020-12-09 13:09:23

How to make read parameter return in bash?

Good day, there is a simple script

regexp="^([a-zA-Z0-9]([a-zA-Z0-9\-]{0,2}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,6}$"
read name
if ; then
   echo "Доменное имя введено верно"
else
   echo "Доменное имя введено неверно"
fi


How can I make it so that when an invalid parameter is entered, the question about entering $name is asked again without exiting the script?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Z
zohan1993, 2020-12-09
@daniks

regexp="^([a-zA-Z0-9]([a-zA-Z0-9\-]{0,2}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,6}$"

while :
do
    read name
    if 
    then
        echo "Доменное имя введено верно"
        break
    else
        echo "Доменное имя введено неверно"
    fi
done

S
Saboteur, 2020-12-09
@saboteur_kiev

regexp="^([a-zA-Z0-9]([a-zA-Z0-9\-]{0,2}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,6}$"

while read; do
    if ; then
        echo "Доменное имя введено верно"
        break
    else
        echo "Доменное имя введено неверно"
    fi
done

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question