Using getopt to parse long options

Using getopt to parse long options

Post by Vikas Agnihotr » Sun, 05 Oct 2003 13:10:12



Red Hat 9.0, getopt (enhanced) 1.1.2

I am trying to use getopt to validate/parse long command line options and
not getting anywhere.

I am doing something like

getopt -l a-long:,b-long: -- "--a-long a --b-long b"

I get

--

Why do I get -- as the output?

How to use this stuff? I am surprised that are so few examples of this to
be found.

Thanks

 
 
 

Using getopt to parse long options

Post by Ed Morto » Sun, 05 Oct 2003 21:41:14



> Red Hat 9.0, getopt (enhanced) 1.1.2

> I am trying to use getopt to validate/parse long command line options
> and not getting anywhere.

> I am doing something like

> getopt -l a-long:,b-long: -- "--a-long a --b-long b"

> I get

> --

> Why do I get -- as the output?

> How to use this stuff? I am surprised that are so few examples of this
> to be found.

> Thanks

Read the thread titled "ksh'93 getopts --longoptions" posted on 26th
September and you'll find, among other things, an example of "getopts".
Yes, I know you asked about "getopt", but maybe that'll give you some ideas.

        Ed.

 
 
 

Using getopt to parse long options

Post by Stephane CHAZELA » Mon, 06 Oct 2003 04:50:31



> Red Hat 9.0, getopt (enhanced) 1.1.2

> I am trying to use getopt to validate/parse long command line options and
> not getting anywhere.

> I am doing something like

> getopt -l a-long:,b-long: -- "--a-long a --b-long b"

You need to specify short options, or the first argument after
"--" is considered as the short option specifications.

Moreover, "--a-long a --b-long b" is passed as a single
argument, so none of the options will be recognized.

getopt -o '' -l a-long:,b-long: -- "--a-long" "a" "--b-long" "b"

or:

getopt -l a-long:,b-long: -- "" "--a-long="a" "--b-long" "b"

--
Stphane