MTC logo MTC logo Midlands Technical College
Prospective StudentsEnrolled StudentsFaculty & StaffCommunity Partners
About
Academics
Continuing Education
Distance Learning
Student Forms
Library
Class Schedule
News & Updates
Calendar
Directory
Site Map
Ask MTC
MTC Jobs Bookstore
Home
navigation
 
Search

 

About MTC Academics Continuing Education Distance Learning Student Forms Library Class Schedule News & Updates Calendar Directory Site Map Ask MTC MTC Jobs Bookstore Home


CPT 247


Quick Reference

Exercise

Shellscript1

 

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