case $timeofday (Photo web hosting) inyes | y | Yes |
Friday, July 27th, 2007case $timeofday inyes | y | Yes | YES ) echo Good Morning ;; n* | N* ) echo Good Afternoon ;; * ) echo Sorry, answer not recognized ;; esacexit 0How It WorksIn this script, we used multiple strings in each entry of the case so that casetests several differentstrings for each possible statement. This makes the script both shorter and, with practice, easier to We also show how the * wildcard can be used, although this may match unintended patterns. For exam- ple, if the user enters never, this will be matched by n* and Good Afternoon will be displayed, whichisn t the intended behavior. Note also that the * wildcard expression doesn t work within quotes. Try It Out Case IIl: Executing Multiple StatementsFinally, to make the script reusable, we need to have a different exit value when the default pattern We also add a setconstruct to show this in action: #!/bin/shecho Is it morning? Please answer yes or no read timeofdaycase $timeofday inyes | y | Yes | YES ) echo Good Morning echo Up bright and early this morning ;; [nN]*) echo Good Afternoon ;; *) echo Sorry, answer not recognized echo Please answer yes or no exit 1;; esacexit 0How It WorksTo show a different way of pattern matching, we change the way in which the nocase is matched. show how multiple statements can be executed for each pattern in the casestatement. Notice careful to put the most explicit matches first and the most general match last. This is importantbecause the casewill execute the first match it finds, not the best match. If we put the *)first, it wouldalways be matched, regardless of what was input.