I've searched online and found many examples using getopts, but nothing that clearly explains it use, nor any examples of what I'm trying to do.
I have a script named "process". It can take from 0 to 3 different options. I'd like to be able to handle these options regardless of the order that they are entered.
Syntax:
process [-v] [-d
#] [-h|-?] [
string]
-v = verbose mode on
-d
# = how deep to do the process, expecting a number parameter
-h or -? = show command usage
string = only process lines containing the specified string
I'd like the user to be able to enter the command freestyle. In other words:
process findme
process -d 3 findme
process findme -d 3
process -v findme -d 3
etc..
This is what I'm currently using and it does not meet my needs as it can't handle the
string parameter:
Code:
verbose=0;
while getopts vhd: optname
do
case "$optname" in
v)
verbose=1
;;
d)
depth="$OPTARG"
;;
h | ?)
echo "How to use this command"
exit
;;
esac
done
How can I process the parameters passed to my script?