case statement for different cmd arguments

Hello friends,

I have a boubt passing different arguments at a time for any one option in below code.
I would also like to check which option has been selected (any one of i, r, u ) so that whether or not matching argument passed can be verified.

for i and r - install and re-install - I want to pass directory path
and for u -upgrade - I want to pass list of patches to be upgraded.

Is there a way I can catch i, r, u option value in a variable and match them with the argument pass for that option.

while getopts :iru: OPTION
        do
         case "$OPTION" in
          i) install="$path install_function" ;;
          r) reinstall="$path Reinstall_Function"     ;;
          u) patch_upgrade=$OPTARG upgrade_function ;;
          :) echo "$0: $OPTARG option missing argument!"
             exit 2 ;;
          ?) echo "$0: $OPTARG is an invalid option!"
             echo "$0 -ab -c optarg patch_list"
             exit 2 ;;
         esac
         done
       shift $OPTIND-1  

Any help would be highly appreciated.

Thanks in advance

PD2

Hello friends,

Your help is highly appreciated to get list of all parameters ($@) passing as an argument to option U in below code - patch_upgrade. Here I am passing list of patches as an argument ( patch count may vary ) for option -u but not sure, what I am missing , I am not able to pass all argument $OPTARG accepts first one only. Where as I wanted a complete list to get l on OPTARG. Please help me correcting below case statement.

install=0
reinstall=""
patch_upgrade=""
# if install and re-install dont need argument but upgrade need
while getopts :iru: OPTION
       do
         case "$OPTION" in
          i ) install="yes"   ;;
          r ) reinstall="on"     ;;
          u ) patch_upgrade=$OPTARG  ;;   # patch_list
          : ) echo "$0: $OPTARG option missing argument!"
              exit 2 ;;
          ? ) echo "$0: $OPTARG is an invalid option!"
              echo "$0 -ir -u optarg patch_list"
              exit 2 ;;
         esac
       done
       shift $((OPTIND-1)); OPTIND=1

if [ $install = "yes" ] ; then
 echo " call install function"
fi 
 
if [ $reinstall = "on" ] ; then
 echo " call Re-install function"
fi
 
 if [ $patch_upgrade = $OPTARG ] ; then
  echo " call patch_Upgrade function "
  echo " list of patches is $OPTARG"
  echo " array of patch list is $@"
 fi

Thank you very much in advance.
-Pd

Seems like every post you have made here has required a moderator to come along and update after you to add Code Tags, they are a lot more patient than me.

Have you considered using a quoted string for list of patches eg:

$ your_code -i -u "patch1 patch3 patch201" testit
Installing testit
Applying patch1.....
Applying patch3.....
Applying patch201.....
All done

DOH!! How I can be so stupid not tried "" or '' ..both are working . but Isn't there a way without puting " " or '' we can treat all passing argument as a string that optarg shud hold.

Any way thank you Chubler , for your quick respond and pointing my mistake. $$ to you .

cheers
Pramod

Well it's not really the standard way unix commands get their args. Usually any list of optional items appear as the last args eg:

command [-i] [-r] [patch [patch ...]]

So everything after last passed arg is assumend to be a patch.