Depends on the shell. You can always do something messy and check for -P/U/F and then 'cut -c2-'.
If you have bash or ksh (and probably some others but I'm ignorant), you can use 'getopts'.
An example below:
------------------------------------------------------
# getoptsScript
while getopts ":abc:d:" opt
do
case $opt in
a) echo "Option a has been passed"
optionA=true
;;
b) echo "Option b has been passed"
optionB=true
;;
c) echo "Option c has been passed"
optargC=$OPTARG
echo "Option c has argument $optargC"
;;
d) echo "Option d has been passed"
optargD=$OPTARG
echo "Option d has argument $optargD"
;;
*) echo "Invalid option - $opt"
;;
esac
done
shift $((OPTIND - 1))
-----------------------------------------------------------------
This script takes options a, b, c and d.
getoptScript -a -b OR getoptScript -ab is exactly the same
The options list (":abc:d:") holds the valid options. Options c and d are suffixed with a ":" which indicates that they require an option argument.
getoptScript -abc "An argument for c" -d "An argument for d"
The $OPTIND variable is incremented when options are processed. If you shift your input parameters by $OPTIND after processing your options, any additional parameters would be set to $1, $2...
e.g.
getoptScript -c "An argument for c" some other values
Would hold some, other and values in $1, $2 and $3 respectively.
HTH