case esac structure
# This shell script identifies number (digit), lower
case letter, UPPER CASE LETTER
# and special character set such as $ & @ … etc
but beware of the # sign character
# structure begin with case and enclosed with
esac
(case spelled backward)
# usage testing
7 assuming the shell script is named testing
#
testing a
#
testing A
character=$1
case “$character” in
[0-9] )
echo “digit” ;;
[a-z] )
echo “lower case letter” ;;
[A-Z] )
echo “UPPER CASE LETTER” ;;
* )
echo “special character” ;;
esac
# Second example using the error
handling subroutine
# error handling routine
if [
$# -ne 1 ]
then
echo " Proper usage is testing with an argument "
echo " For example testing W “
exit 1
fi
character=$1
case “$character” in
[0-9] )
echo “digit” ;;
[a-z] )
echo “lower case letter” ;;
[A-Z] )
echo “UPPER CASE LETTER” ;;
* )
echo “special character” ;;
esac
|