help using if/and/or statement

greetings,

the goal below is to test the supplied options/arguments for validity. if the matlab option is not supplied with the additional option of a file then exit. however if matlab IS supplied with its companion option of a file OR batch is the only option then continue on. it's clear the -a -n thing isn't working correctly. hopefully i've explained it well enough and the code below at least conveys my intention. any insight would be appreciated.

if [ "$CODE" = "comsol" ]; then
        if [ "$PASS_OPTS" = " matlab" ] && [ -z "$PASS_OPTS2" ]; then
                Fatal "You must use --opts matlab --opts2 filename.m"
        else
                if [ "$PASS_OPTS" = " matlab" -a -n "PASS_OPTS2" ] || [ "$PASS_OPTS" = " batch" ]; then
                       case "$CPUS" in
                       ( 12|24|36 )
                       export AMT=$(expr $CPUS / 12)
                       RUSAGE="rusage[lic_req_comsol=1:duration=15]"
               ;;
                       ( * )
                       echo ""
                       Fatal "You must either specify 12, 24 or 36 cpus for code Comsol"
               ;;
                       esac
                fi
        fi
fi

Hi,

Instead of

try the below statement.

Thanks,
Kalai

1 Like

greetings kalai,
sorry but that didn't work as RUSAGE didn't get set.
joe.

---------- Post updated at 09:28 AM ---------- Previous update was at 08:31 AM ----------

greetings kalai,
sorry, you had it right all along, a typo on my part was the goof! thanx for your help!!

You might want to read up on the getopts command, which can do argument processing for you in a consistent manner. Here's one sample of many I just found: Illustrated UNIX System V/BSD: Module 59 getopts (ksh)
If you ask the Google there are lots of other examples. Why reinvent the wheel when there is a facility built into the shell to do it already?

Gary

1 Like