getopt in unix
Hi,
Can anyone tell me how to go about using getopt function to get the command line options given in linux shell???? I also want to know how to handle error situations ( say an option -u needs an argument, but we haven't given it... etc) Thanks, Hari. |
Use man:
Code:
man <command> |
Re
Hi,
I posted this query after going thru man and searching thru the web for some time. It didn't make much sense This is the part of my code ... while getopts 'd:r:u:p:l' OPTION do case "$OPTION" in d) SAVE_PATH="$OPTARG";; r) DEST_IP="$OPTARG";; u) USER_NAME="$OPTARG";; p) PASSWORD="$OPTARG";; l) LOCAL=TRUE;; ?) Usage # calls an error message generating function esac done the problem that i am having is that if i give the pgm like this $xyz -d -r 1.2.3.4 -l, instead of giving an error saying that the argument for -d isn't provided it takes "-r" as the argument for "-d". what am i doing wrong here. Thanks a lot, Hari. |
All times are GMT -5. The time now is 10:20 PM. |