在 shell 脚本中退出 while 循环
Come out of while loop in shell scripting
我有以下代码
echo "Please Enter the Email Id"
while read -r email
do
if
echo "$email" | grep -v "awt"
then
echo "You entered a invalid email id please try again"
break
fi
echo "================You chose Email id as $email"
done
echo "Please Enter the user Name"
read -r name
echo "you entered $name"
echo Final email id $email
echo final name $name
当我试图执行上面的代码时,我无法进入第二个条件,即它没有跳出循环。
我需要的是它应该询问直到用户输入正确的电子邮件 ID,然后它应该转到下一组代码并最终打印最终的 echo 语句
你可以这样做:
while :; do
read -rp 'Please Enter the Email Id: ' email
if [[ $email != *awt* ]]; then
echo "You entered an invalid email id please try again"
else
break
fi
done
我有以下代码
echo "Please Enter the Email Id"
while read -r email
do
if
echo "$email" | grep -v "awt"
then
echo "You entered a invalid email id please try again"
break
fi
echo "================You chose Email id as $email"
done
echo "Please Enter the user Name"
read -r name
echo "you entered $name"
echo Final email id $email
echo final name $name
当我试图执行上面的代码时,我无法进入第二个条件,即它没有跳出循环。 我需要的是它应该询问直到用户输入正确的电子邮件 ID,然后它应该转到下一组代码并最终打印最终的 echo 语句
你可以这样做:
while :; do
read -rp 'Please Enter the Email Id: ' email
if [[ $email != *awt* ]]; then
echo "You entered an invalid email id please try again"
else
break
fi
done