February 2001
Beginner to intermediate
448 pages
9h 2m
English
You might find yourself generating a series of if/elif/elif/elif/else syntax and wondering whether a better way of handling a multiway test exists. The case statement provides a succinct way to express multiway tests. This construct is similar to a switch statement in some programming languages and is vaguely similar to computed go tos. The syntax checks a certain value against several cases. Each case is terminated by ;;, and the value to be tested appears after the case syntax. The syntax is as follows (keywords are bold):
case test_variable in test_pattern1) command(s) ;; test_pattern2) command(s) ;; pattern3|or_pattern4) command(s) ;; *) commands_to_execute_for_default_case ;; esac
The patterns can include file matching ...
Read now
Unlock full access