LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-01-2004, 03:29 AM   #1
hari_s_82
LQ Newbie
 
Registered: Sep 2004
Posts: 20

Rep: Reputation: 0
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.
 
Old 10-01-2004, 03:39 AM   #2
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 11,737

Rep: Reputation: 1585Reputation: 1585Reputation: 1585Reputation: 1585Reputation: 1585Reputation: 1585Reputation: 1585Reputation: 1585Reputation: 1585Reputation: 1585Reputation: 1585
Use man:
Code:
man <command>
 
Old 10-01-2004, 04:19 AM   #3
hari_s_82
LQ Newbie
 
Registered: Sep 2004
Posts: 20

Original Poster
Rep: Reputation: 0
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
getopt() function in visual C++ KissDaFeetOfSean Programming 1 07-14-2005 11:47 PM
getopt availability Bostonian Programming 2 12-26-2004 10:37 AM
getopt(3) Berhanie Programming 8 06-15-2004 09:50 PM
Getopt() newbie... AMMullan Programming 6 02-11-2004 01:02 PM
Using getopt in cplus UltimaGuy Programming 3 08-28-2003 05:35 AM


All times are GMT -5. The time now is 08:42 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration