Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
case
case value in
 pattern1) cmds1;;
 pattern2) cmds2;;
 .
 .
 .
esac

Execute the first set of commands (cmds1) if value matches pattern1, execute the second set of commands (cmds2) if value matches pattern2, etc. Be sure the last command in each set ends with ;;. value is typically a positional parameter or other shell variable. cmds are typically Unix commands, shell programming commands, or variable assignments. Patterns can use file-generation metacharacters. Multiple patterns (separated by |) can be specified on the same line; in this case, the associated cmds are executed whenever value matches any of these patterns. See the Examples here and under eval .

The shells allow pattern to be preceded by an optional open parenthesis, as in ( pattern ). In Bash and ksh88, it's necessary for balancing parentheses inside a $() construct.

The Korn shell allows a case to end with ;& instead of ;;. In such cases, control "falls through" to the group of statements for the next pattern.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial