Case statement

Hello,
The standard case statement :-

case "$1" in
"IE0263")
commands;;
"IE0264")
commands;;
esac

is it possible to have :-

case "$1" in
"IE0263" OR "IE0878")
commands;;
"IE0264")
commands;;
esac

Thanks

You should insert your code properly, it would be readable a lot better. But this just as an aside. Yes, you can do as you want using the pipe char ("|"). You can even use glob characters to create "default" branches:

#! /bin/ksh

case $1 in
     a|b)
          echo "param was a or was b"
          ;;

     c)
          echo "param was c"
          ;;

     *)
          echo "param was neither a nor b nor c"
          ;;

esac
exit 0

I hope this helps.

bakunin

Beware of where you put quotes in relation to the pipe (OR operator). This illustrates the issue:

case "$1" in
"IE0263|IE0878")
        echo "Version 1 : Found IE0263 OR IE0878"
        ;;
"IE0263"|"IE0878")
        echo "Version 2 : Found IE0263 OR IE0878"
        ;;
"IE0264")
        echo "Found: IE0264"
        ;;
esac


./scriptname IE0878
Version 2 : Found IE0263 OR IE0878

Although inside the case statements there is is no need for quotes around $1 and you only need quotes around the case patterns if it contains special characters or spacing.

case $1 in
  IE0263|IE0878)
    echo "Found IE0263|IE0878"
  ;;
  IE0264)
    echo "Found: $1"
  ;;
esac

Before esac you can also add the following code:

  *)
    echo "UNKNOWN"
  ;;

Edit - didn't see that bakunin already mentioned *) option