Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 25 Sep 2002 21:58:43 -0400
From:      "Matthew Emmerton" <matt@gsicomp.on.ca>
To:        <freebsd-hackers@freebsd.org>
Subject:   perceived strangeness with getopt(1,3)
Message-ID:  <009b01c26500$3f7e91a0$1200a8c0@gsicomp.on.ca>

next in thread | raw e-mail | index | archive | help
Maybe I'm missing something huge, but getopt(1,3) aren't working the way I
think they should.

I have a script that I want to take two options, both of which have required
arguments.

gabby# getopt k:s: -k
getopt: option requires an argument -- k
 --
gabby# getopt k:s: -s
getopt: option requires an argument -- s
 --
gabby#

Ok, so far, so good.  But now let's combine them:

gabby# getopt k:s: -k arg1 -s arg2
 -k arg1 -s arg2 --

Ok, looks fine.

gabby# getopt k:s: -k -s
 -k -s --
gabby#

Wha?  Neither of these options specified arguments!  I guess you could
consider that -k's argument was '-s', but I was pretty sure that an option's
argument couldn't start with a dash character (to avoid the ambiguity that
I'm hitting right now.)

I'm pretty sure I'm the one that's confused (not getopt), since I get the
same behaviour on -STABLE and -CURRENT.  Can someone tell me how to
accomplish what I want to do?  Basically, I want this:

gabby# getopt k:s: -k arg1 -s
getopt: option requires an argument -- k
 -k arg1 --
gabby# getopt k:s: -k -s arg2
getopt: option requires an argument -- k
 -s arg2 --
gabby#

--
Matt Emmerton


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?009b01c26500$3f7e91a0$1200a8c0>