我有使用if条件写的大写或小写字符检查,如何用case语句?
char=""
echo "Type char:"
read char
if [ $char = ${char^} ]; then
echo "upper case"
elif [ $char = ${char,,} ]; then
echo "lower case"
else
echo "neither"
fi
答案 0 :(得分:2)
例如:
[STEP 101] $ cat foo.sh
shopt -s extglob
read -p "Type char: " ch
case $ch in
+([[:lower:]])) echo lowercase;;
+([[:upper:]])) echo uppercase;;
*) echo neither;;
esac
[STEP 102] $ ./foo.sh
Type char: abc
lowercase
[STEP 103] $ ./foo.sh
Type char: ABC
uppercase
[STEP 104] $ ./foo.sh
Type char: aBc
neither
[STEP 105] $