Unix Shell - parsing options with getopts

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > October 2004 > parsing options with getopts





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author parsing options with getopts
Morten Seeberg

2004-10-04, 6:01 pm

Is there any way to use more descriptive options such as:

-option1 blabla -option2 blabla
instead of just
-o blabla -p blabla

I havent been able to find anything about it or make i work with getopts...

~~~~~~~~~~~~~~~
/\/\orten $eeberg

remove x for reply


Eric Moors

2004-10-04, 6:01 pm

Morten Seeberg wrote:

> Is there any way to use more descriptive options such as:
>
> -option1 blabla -option2 blabla
> instead of just
> -o blabla -p blabla
>
> I havent been able to find anything about it or make i work with
> getopts...


At least for linux there is getopt.
A commandline parser to be used from scripts.
That can deal with long options
I am not sure about other OS's

Eric
Morten Seeberg

2004-10-04, 6:01 pm

As I was still googling around, i noticed this being called longoptions, and
found the thread:
ksh'93 getopts --longoptions


"Morten Seeberg" <xml@seeberg.dk> wrote in message
news:sx88d.1963$ZH1.598@news.get2net.dk...
> Is there any way to use more descriptive options such as:
>
> -option1 blabla -option2 blabla
> instead of just
> -o blabla -p blabla
>
> I havent been able to find anything about it or make i work with

getopts...


Dana French

2004-10-04, 6:01 pm

"Morten Seeberg" <xml@seeberg.dk> wrote in message news:<sx88d.1963$ZH1.598@news.get2net.dk>...
> Is there any way to use more descriptive options such as:
>
> -option1 blabla -option2 blabla
> instead of just
> -o blabla -p blabla
>
> I havent been able to find anything about it or make i work with getopts...



Some implementations of "getopts" will allow long options, however
that is not portable across platforms. There is an example ksh93
function called "getwordopts_k93" that allows the use of words as
options at the following URL:

http://www.mtxia.com/fancyIndex/Too...x/find_k93.html

This function is not intended as a replacement for "getopts", it is
merely intended to solve a specific problem for the "find_k93"
function. You may be able to modify this function for your specfic
needs.

--------------------------------------------------------
Dana French dfrench@mtxia.com
Mt Xia Technical Consulting Group http://www.mtxia.com
100% Spam Free Email http://www.ridmail.com
MicroEmacs http://uemacs.tripod.com
Korn Shell Web http://dfrench.tripod.com/kshweb.html
Janis Papanagnou

2004-10-04, 6:01 pm

Morten Seeberg wrote:
> Is there any way to use more descriptive options such as:
>
> -option1 blabla -option2 blabla
> instead of just
> -o blabla -p blabla
>
> I havent been able to find anything about it or make i work with getopts...


As others pointed out already, ksh93 supports that feature.

The only somewhat elaborate source of documentation with
examples that I have found yet is a book of Rosenblatt
("Learning Korn Shell" was the title, I think).

Janis
Eric Moors

2004-10-07, 2:56 am

Morten Seeberg wrote:

> Is there any way to use more descriptive options such as:
>
> -option1 blabla -option2 blabla
> instead of just
> -o blabla -p blabla
>
> I havent been able to find anything about it or make i work with
> getopts...


At least for linux there is getopt.
A commandline parser to be used from scripts.
That can deal with long options
I am not sure about other OS's

Eric
Morten Seeberg

2004-10-07, 2:56 am

As I was still googling around, i noticed this being called longoptions, and
found the thread:
ksh'93 getopts --longoptions


"Morten Seeberg" <xml@seeberg.dk> wrote in message
news:sx88d.1963$ZH1.598@news.get2net.dk...
> Is there any way to use more descriptive options such as:
>
> -option1 blabla -option2 blabla
> instead of just
> -o blabla -p blabla
>
> I havent been able to find anything about it or make i work with

getopts...


Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com