如何打印行直到有效的电子邮件ID进入shell?

时间:2017-08-05 13:31:30

标签: bash shell awk sed

#!/bin/sh

while read line 
do
    echo "Name: " "$line"
    while []; do
        #statements
    done
done <input.txt

1 个答案:

答案 0 :(得分:-2)

验证输入时使用break。 例如:

while read -rp "Please enter email address " line ; do
   if [[ "$line" =~ ^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$ ]]; then
      echo OK
      break
   else
      echo "Try again"
   fi
done