Computing.Net > Forums > Unix > getopts exclusive arguments

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

getopts exclusive arguments

Reply to Message Icon

Name: ghjellyn
Date: June 25, 2007 at 02:58:23 Pacific
OS: HPUX
CPU/Ram: ...
Product: ...
Comment:

hi all

i got a ksh script where i want to do the following :

there are 3 possible arugments : a, b ,c and only one of them can be called.

#foo -a
is ok

#foo -b -c
is not ok

so i wrote the getopts part :

while getopts abc options
do
case $option in
a)...
b)...
c)...

esac

what is a "clean way of checking that only one option (a or b or c) is used?

tnx




Sponsored Link
Ads by Google

Response Number 1
Name: lankrypt0
Date: June 25, 2007 at 09:02:09 Pacific
Reply:

I would actually do a simple if

if [[ $2 != "" ]];then
FAIL
else
while getopts abc options
do
case $option in
a)...
b)...
c)...

esac
fi

That will check for any input for the second argument.


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: getopts exclusive arguments

getopts command www.computing.net/answers/unix/getopts-command/4416.html

getopts for bourne www.computing.net/answers/unix/getopts-for-bourne/4852.html

CSH Runtime Arguments www.computing.net/answers/unix/csh-runtime-arguments/3825.html