Unix Korn Shell script on Solaris to DB2 UDB LUW database

I am rather new to korn shell scripting and attempting to write a Unix script that would detach, attach a range partition table in DB2 UDB LUW database. This would be a job scheduled in control M that reads in an input file with 5 parameters passed to it from the application. I don't have much Unix scripting experience (I am a DB2 UDB LUW DBA) and looking for some direction and possibly sample scripts to see how this could be accomplished

If you ask questions it is always a good idea to provide some sample data as example for what you have and what you want to achieve. Otherwise it is difficult to suggest.

If i get you correctly you have a file (?) with five parameters stated in it (?) and your script is called, has to open the file and retrieve the parameters from it, yes?

Ok, i don't know your file format, but let's suppose its name is "/path/to/param.file" and it looks like that:

param1="some-value-1"
param2="some-value-2"
param3="some-value-3"
param4="some-value-4"
param5="some-value-5"

Further i suppose that the five parameters are fixed and you know in advance which parameters to expect (the values could differ, but the parameters names do not). Your script could look like this:

#! /bin/ksh

# .... set some environment first, whatever is needed here ....

typeset  fParam="/path/to/param.file"
typeset  chLineBuffer=""

typeset  achParm[1]=""
typeset  achParm[2]=""
typeset  achParm[3]=""
typeset  achParm[4]=""
typeset  achParm[5]=""

typeset -i iCnt=0
typeset -i lError=0

# read the file (cat), strip all empty lines and comments (sed) and feed the rest to
# the while-loop. There the "case..esac" decides which parameter it is and
# stores it to the appropriate variable. If the parameter is not known an error
# is issued and the script terminates with errorlevel 1.

cat "$fParam" |\
sed 's/^[<spc><tab>]*$//; s/#.*$//' |\
while read chLineBuffer ; do
     case "${chLineBuffer%%=*}" in
          param1)
               achParm[1]="${chLineBuffer##*=}
               ;;

          param2)
               achParm[2]="${chLineBuffer##*=}
               ;;

          param3)
               achParm[3]="${chLineBuffer##*=}
               ;;

          param4)
               achParm[4]="${chLineBuffer##*=}
               ;;

          param5)
               achParm[5]="${chLineBuffer##*=}
               ;;

          *)
               print - "ERROR: unknown parameter $chLineBuffer"
               exit 1
               ;;
     esac
done

# The following part is only necessary if you need to make sure that all five
# parameters are passed. If it is legal to have one or more ommitted you do
# not need this.

iCnt=1
lError=0
while [ $iCnt -le 5 ] ; do
     if [ -z "${achParm[$iCnt]}" ] ; then
          print - "ERROR: no Value for achParm[$iCnt]"
          lError=1
     fi
done
if [ $lError -gt 0 ] ; then
     exit 2
fi

# Put the part which works with the gotten parameters here, for example:

some-command -a "${achParm[1]}" -b "${achParm[2]}" -c "${achParm[3]}"

exit $?

I hope this helps.

bakunin