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

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.