Unix Shell Script Case Statement

May 15, 2007 by Mark Marucot 

The case statement is similar to if .. else if .. else statement which performs specific statement/s if there are three or more conditions.
Syntax:

CODE:
  1. case word in
  2. value1) statements
  3. value2) statements
  4. *) statements
  5. esac

Example:

CODE:
  1. !#/bin/sh
  2. case $1
  3. in
  4. 1) echo ‘First Choice’;;
  5. 2) echo ‘Second Choice’;;
  6. *) echo ‘Other Choice’;;
  7. esac

Related Posts

Comments

Feel free to leave a comment...
and oh, if you want a pic to show with your comment, go get a gravatar!