Control Commands

The Korn shell provides a number of control-flow commands typically found in high-level programming languages. The following sections cover these special commands.

The case Command

The case command provides multiple-branch capability. It is used to compare a single value against a number of other values. Commands associated with that value are executed when a match is made. The syntax for the case command is:

						case
						value
						in
						pattern1)
						command
						command;; 
       pattern2)
						command
						command;; 
       . . . 
       patternn)
						command
						command;; 
esac
					

where value is compared to pattern1, pattern2, ... patternn. When a match is found, the commands associated with that pattern up to the double semi-colons are executed.

The following Korn shell script demonstrates ...

Get Korn Shell: Unix and Linux Programming Manual, Third Edition, The now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.