help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Handling getopt for option without optional argument value


From: lisa-asket
Subject: Handling getopt for option without optional argument value
Date: Fri, 23 Jul 2021 18:32:00 +0200 (CEST)

How is it that people avoid long options, they are good instruments to use.



libc has the long option function, whilst bash is the most widely used shell 
packaged

by default for most distributions, making the use of long options in bash 
functions

extremely useful.


From: Dennis Williamson <dennistwilliamson@gmail.com>
To: lisa-asket@perso.be
Subject: Re: Handling getopt for option without optional argument value
Date: 23/07/2021 18:21:30 Europe/Paris
Cc: Greg Wooledge <greg@wooledge.org>;
   help-bash <help-bash@gnu.org>



On Fri, Jul 23, 2021, 10:50 AM <lisa-asket@perso.be> wrote:

Things get complicated because people tell you that if you want to handle 

--gnu-long-opts you have to write your own parser.



You say there is getopts.  The job got to be finished, not done half way.

So we can all use the built-in. But you just tell people, don't do long options.

 



If you really must use long options, write your program in Python and use its 
argparse module. It can probably do anything you could want. And write the rest 
of your program in Python as well. 



However, if you want to be perverse, use it inside your Bash script just to 
parse your options and arguments. You would have to devise a way for the Python 
part to output something that the Bash part could act on. Perhaps by perversely 
using getopts.







reply via email to

[Prev in Thread] Current Thread [Next in Thread]