
case | 655
Bash and Korn
This is the Title of the Book, eMatter Edition
Copyright © 2006 O’Reilly & Associates, Inc. All rights reserved.
added built-in version is used only if a path search would other-
wise have found a command of the same name. (This allows
replacement of system commands with faster, built-in versions.)
Otherwise, the built-in command is always found.
Options
-d Delete the built-in command name.
-f Load new built-in command from library.
-s Only print “special” built-ins (those designated as special by
POSIX).
case
case value in
pattern1) cmds1;;
pattern2) cmds2;;
.
.
.
esac
Execute the first set of commands (cmds1)ifvalue matches
pattern1, execute the second set of commands (cmds2)ifvalue
matches pattern2, etc. Be sure the last command in each set ends
with ;;. value is typically a positional parameter or other shell vari-
able. 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 paren-
thesis, 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