LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   getopt in unix (https://www.linuxquestions.org/questions/linux-newbie-8/getopt-in-unix-237423/)

hari_s_82 10-01-2004 03:29 AM

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.

bathory 10-01-2004 03:39 AM

Use man:
Code:

man <command>

hari_s_82 10-01-2004 04:19 AM

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 05:45 PM.