Using "while getopts" in a script (script experts needed)

PhillyPhoto
Valued Contributor

I'm working on a script to check if an application is installed, if it is, what the version is. When I wrote the script and tested locally it worked fine, but I forgot the script in Jamf is actually passing the entire string as option 4, and won't pick up the individual arguments I used. This is the code that works fine on my machine:

while getopts "o:O:p:t:T:v:c:fsr?" opt
do
    case "${opt}" in
        o) osMinVers=${OPTARG};;
        O) osMaxVers=${OPTARG};;
        p) appPath=${OPTARG};;
        t) jamfTrigger=${OPTARG};;
        T) patchName=${OPTARG};;
        v) appToUpdVers=${OPTARG};;
        c) verCheck=${OPTARG};;
        f) installIfMissing="true";;
        s) silent="true";;
        r) reboot="true";;
        ?) echo "Usage: macOSUpgradePrePostReqs.sh -o -O -p -t -T -v [-f -s -r]";
           echo "      -o <osMinVers>";
           echo "      -O <osMaxVers>";
           echo "      -p <appPath>";
           echo "      -t <jamfPatchTrigger>";
           echo "      -T <patchName>";
           echo "      -v <appToUpdVers>";
           echo "      -c Greater then or less then";
           echo "         g/G = application must be greater than the version specified";
           echo "         l/L = application must be less than the version specified";
           echo "      -f Install if Missing";
           echo "      -s Silent";
           echo "      -r Reboot";
           exitFunc 90
    esac
done

My argument string is:

-o 18G1 -O 22Z9999 -p "/Applications/Symantec Endpoint Protection.app" -t SEPRemoval -T "Symantec Removal" -v 14.3.5055.3000 -c g

Any suggestions?

0 REPLIES 0