suppose I have a script like so: (let's call it test.sh)
#!/bin/sh
function php() {
    printf "The rhost is ${RHOST} and the lport is ${LPORT}"
}
while getopts "hr:l:s:" arg; do
    case $arg in
        h)
            printf "Usage\n"
        ;;
        r)
            RHOST=$OPTARG
        ;;
        l)
            LPORT=$OPTARG
        ;;
        s)
            SHELL=$OPTARG
            if [[ "$SHELL" == "php" ]] || [[ "$SHELL" == "PHP" ]] ; then
                php
            fi
       ;;
    esac
done
If I run my script like "test.sh -r 10 -l 4 -s php"
My script will perform like I want...
However, if I run it like "test.sh -s php -r 10 -l 4"
rhost and lport variables never make it to the php function. I realize this is because it's being called first. However, my question is, how can I write the script, so that no matter the order of the way the arguments are run, I can still use rhost and lport as variables?
I have also tried playing with shift, but I am guessing that is not the answer or I am placing the shift command in the wrong spot.
 
    