How to check if an argument has a single character in shell
arguments, character, grep, shell
Solution
You was very close !
if echo $1 | egrep -q '^[A-Z]$';
then echo "Uppercase";
elif echo $1 | egrep -q '^[a-z]$';
then echo "Lowercase";
else
echo "FAIL";
fi
- I've just added the special characters `^` & `$`, means respectively start of line & end of line
- no need `egrep` there, `grep` is sufficient
Problem
I'm trying to make a script to check if an argument has a single uppercase or lowecase letter, or if its anything else (a digit or a word for example.) So far got this done: ``` if echo $1 | egrep -q '[A-Z]'; then echo "Uppercase"; elif echo $1 | egrep -q '[a-z]'; then echo "Lowercase"; else echo "FAIL"; fi ``` Need to make it to fail me not only if it isnt a letter, but if I insert a word or 2 letters.