Hi Experts,
I've a script where users will input the email id. I want to loop the script until the user enter proper email id.
Its validating for all condition and error out if any wrong data, but for one condition alone its not erroring out.
Capture_EmailID()
{
echo -e "Please Enter email id, Incase you want to enter for muliple email id's please enter all separated by ',' in a single line like below"
echo -e "abc@app.com,def@app.com"
echo -e "\033[0;36mEnter the email id/ids \033[0;37m"
read MAIL_ID
Validate_Email "$MAIL_ID"
echo -e "Email Validation Completes, Reports will be send to - \033[0;32m$MAIL_ID\033[0;37m"
}
Validate_Email()
{
echo $1 | awk -F',' '{for(c=1;c<=NF;c++) print $c}' | while read line
do
nocomma_error_count=$(echo $line | sed 's/com/com\n/g' | grep -c com)
if [ "$nocomma_error_count" -ge 2 ] ; then
echo -e "\033[0;31mERROR ::: NOT VALID EMAIL ID - $line having $error_count email id's not separated by comma (,) \033[0;37m"
Capture_EmailID
else
format_error_count=$(echo $line | grep "^[a-zA-Z0-9.]*@app.com$")
[ "$format_error_count" == "" ] && echo -e "\033[0;31mERROR ::: NOT VALID EMAIL ID $line\033[0;37m" && Capture_EmailID
fi
done
}
Validation steps
- It needs to validate if the email id ending with app.com
- If multiple email id entered, then it need to check for each email id with the format and separated by comma or not
Below is validation missing happening when i enter one correct and one wrong email id. The script is not asking for read command
$Capture_EmailID
Please Enter email id, Incase you want to enter for muliple email id's please enter all separated by ',' in a single line like below
abc@app.com,def@app.com
Enter the email id/ids
abc@app.com,def@app.comabc@app.com
ERROR ::: NOT VALID EMAIL ID - def@app.comabc@app.com having email id's not separated by comma (,)
Please Enter email id, Incase you want to enter for muliple email id's please enter all separated by ',' in a single line like below
abc@app.com,def@app.com
Enter the email id/ids
Email Validation Completes, Reports will be send to -
Email Validation Completes, Reports will be send to - abc@app.com,def@app.comabc@app.com
$