O'Reilly logo

Practical UNIX by Steve Moritsugu - DTR Business Systems

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Selecting From a Menu of Items

If you want your script to give someone a set menu of options and then want to act on his responses, the case statement is a convenient way to do it. It takes the following form:

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

Here, value is any text string that will be compared with the patterns pattern1, pattern2,and so on to patternx. The command list following the first pattern that matches value will be executed. Usually, a catch-all pattern (such as *) will be used as the last pattern to catch anything that you weren’t expecting or that the user mistyped. Note the required double semicolons (;;) after the last command in each pattern section. Don’t forget ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required