Optargs????

Hi

I am sorry if my query is too simple ......

Can anybody explain the usage of optargs in shell script with options having arguments associated with them.

Thanks in advance !!!

have you looked at the man page for getopt or the shell documentation for getopts?

Actually i am not having any unix console right now. Otherwise i could have checked that.
PLease help me with an example !!!

Thanks

I might help you out. Since I am out of town(family issues), I dont have my references, but when I come back next Thursday, I would give you a hit.

google is your friend. there is a ton of documentation out there on this.
search for "shell getopt example" and you will have hours of fun reading.

Thanks danny !!!

I would appreciate if any sort of information can come right now from anybody !!!

google + search "getopts"

Consider the following loop.
This allows three command line options , one of which accepts an argument(b),
because "b" is followed by a ":" in the getopts arguments.
When processing option b , $OPTARG holds the argument to this option.

while getopts "ab:c" opt; do
case $opt in
a ) process option -a ;;
b ) process option -b
$OPTARG is the option's argument ;;
c ) process option -c ;;

        esac

done

The following while statement loops through all the options and sets them to the corresponding variable. getopts returns true while there are options to be processed. The argument string, here �hw:e:u:m:d�, specifies which options the script accepts. If the user specifies an option which is not in this string, it sets $optionName to ?. If the option is succeeded by a colon, the value immediately following the option is placed in the variable $OPTARG.

while getopts "hw:e:u:m:d" optionName; do
case "$optionName" in
h) printHelpAndExit 0;;
d) debug="0";;
w) whatTowatch="$OPTARG";;
e) email="$OPTARG";;
u) startAtUid="$OPTARG";;
m) maxCpuUsage="$OPTARG";;
[?]) printErrorHelpAndExit "$badOptionHelp";;
esac
done