Quote:
Originally Posted by basildon
Hi
I used this snippet of code to test whether a variable contains solely alphabetic characters.
case $var in
[A-Za-z]) echo "alpha"
;;
*) echo "not alpha "
;;
esac
Testing the $var with all alphabetic characters resulted in the "not alpha" outcome
Could anyone please advise what is wrong?
Thanks
|
Everything is correct, but you are writing the regex for one character.
[A-Za-z] will match a single character, so when you type a string it won't match. Change the regex to [A-Za-z]*
* ---> More than one character or combinations of this.....for more info...check out regular expressions.