If else structure created with shell script operators
{
// shell script snippet A
} && {
// shell script snippet B
} || {
//shell script snippet C
}
snippet A executes, B will execute upon successful execution of script A & C will execute upon unsuccessful execution of script A.
grep is a linux command based tool to search the string match pattern' s where -E option for extended regular expression evaluation.
#!/bin/bash
email="test@gmail.com"
#Email Validation
{
echo | grep -E "^[a-z0-9!#\$%&'*+/=?^_\`{|}~-]+(\.[a-z0-9!#$%&'*+/=?^_\`{|}~-]+)*@([a-z0-9]([a-z0-9-]*[a-z0-9])?\.)+[a-z0-9]([a-z0-9-]*[a-z0-9])?\$"
} && {
echo "Valid E-Mail Address"
} || {
echo "Invalid E-Mail Address"
exit 1
}
No comments:
Post a Comment