Using pattern lists in Unix

Here is the small reminder about the syntax of the “case” command and the usage of the pattern lists.

#!/bin/ksh
print -n "Please enter the line: "
read line

case "$line" in
 ?(dog|cat)  ) print "zero or one occurrence of any pattern" ;;
 *(low|high) ) print "zero or more occurrences of any pattern" ;;
 @(duncan|methos) ) print "exactly one occurrence of any pattern" ;;
 +(rudolph|blitzen) ) print "one or more occurrence of any pattern" ;;
 !(grinch|babay) ) print "everything except patterns" ;;
 -@([hH?]) )  print "Some help..." ;;
 -v*(erbose) ) print "Some more words..." ;;
 *) print "Something else..." ;;
esac

Leave a Reply

  

  

  

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>