Quote:
Originally Posted by troop
Code:
#!/bin/bash
test="gtw3 tw"
if [[ "$test" =~ ^[A-Za-z] ]]; then
echo "ok"
else
echo "Invalid input"
exit 1
fi
|
That did work. However, for sake of code cleanliness, I was hoping for the syntax to say: If the variable does not begin with a letter of the alphabet (regardless of capitalization), then display an error message and exit with status code 1. Is this possible?
The reason is because if I go with your code, this is how it would look:
Code:
if [[ "$interface" =~ ^[A-Za-z] ]]; then
echo "" >/dev/null
else
echo "
ERROR 7: No usable interface label detected.
"
exit 1
fi
Thank you for your reply. You gave much more information than my weak Googling skills gave me.
