2005-09-20 21:31:55 +08:00
|
|
|
|
|
|
|
\section switch switch - conditionally execute a block of commands
|
|
|
|
|
|
|
|
\subsection switch-synopsis Synopsis
|
|
|
|
<tt>switch VALUE; [case [WILDCARD...]; [COMMANDS...];...] end</tt>
|
|
|
|
|
|
|
|
\subsection switch-description Description
|
|
|
|
|
|
|
|
The \c switch statement is used to perform one of several blocks of
|
|
|
|
commands depending on whether a specified value equals one of several
|
|
|
|
wildcarded values.
|
|
|
|
|
|
|
|
\subsection switch-example Example
|
|
|
|
|
2006-01-24 07:17:06 +08:00
|
|
|
If the variable \$animal contains the name of an animal, the
|
2005-09-20 21:31:55 +08:00
|
|
|
following code would attempt to classify it:
|
|
|
|
|
|
|
|
<p>
|
|
|
|
<pre>
|
|
|
|
switch $animal
|
|
|
|
case cat
|
|
|
|
echo evil
|
|
|
|
case wolf dog human moose dolphin whale
|
|
|
|
echo mammal
|
2006-01-24 07:17:06 +08:00
|
|
|
case duck goose albatross
|
2005-09-20 21:31:55 +08:00
|
|
|
echo bird
|
|
|
|
case shark trout stingray
|
|
|
|
echo fish
|
|
|
|
end
|
|
|
|
</pre>
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
|
|
|
|
If the above code was run with \$animal set to \c whale, the output
|
2006-01-24 07:17:06 +08:00
|
|
|
would be \c mammal.
|
2005-09-20 21:31:55 +08:00
|
|
|
|
|
|
|
</p>
|