[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: getopt does not support optional arguments to options
From: |
Andreas Kusalananda Kähäri |
Subject: |
Re: getopt does not support optional arguments to options |
Date: |
Fri, 27 Aug 2021 02:07:56 +0200 |
On Thu, Aug 26, 2021 at 11:47:24PM +0000, nigelberlinguer wrote:
>
>
>
> Sent with ProtonMail Secure Email.
>
> ‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
> On Thursday, August 26, 2021 11:42 PM, Andreas Kusalananda Kähäri
> <andreas.kahari@abc.se> wrote:
>
> > On Thu, Aug 26, 2021 at 09:58:58PM +0000, nigelberlinguer via wrote:
> >
> > > - Have been told that getopt does not support optional arguments to
> > > options. Either you declare the option with : (and failing to provide an
> > > argument is an error); or you don't (and providing an argument is an
> > > error). Is this true, with no workarounds ? Then I have to write the
> > > parsing myself, right ?.
> >
> > getopt is not a bash thing (like e.g. the built-in getopts is). It's an
> > external utility provided by some other software package on your system.
> > On GNU systems, this is usually provided by a "util-linux" package,
> > while BSD systems have a different and incompatible variant in their
> > base system.
> >
> > You will find an example of the use of the GNU getopt utility that
> > includes optional option-arguments in the "util-linux" source
> > distribution:
> >
> > https://salsa.debian.org/debian/util-linux/-/blob/master/misc-utils/getopt-example.bash
>
> Was meaning to say getopts.
>
I know.
Here's from today on this list (no replies yet):
https://mail.gnu.org/archive/html/help-bash/2021-08/msg00190.html
Parts of this thread also deals with this:
https://mail.gnu.org/archive/html/help-bash/2021-08/msg00050.html
This recent thread also starts out talking about getopt, bet then
touches on getopts and the issue of optional option-arguments:
https://mail.gnu.org/archive/html/help-bash/2021-07/msg00163.html
The answers to the following StackExchange issue did not get much love
from the community, but may contain some code that you could use (with
attribution, obviously):
https://unix.stackexchange.com/questions/663803/can-you-make-a-bash-scripts-option-arguments-be-optional
--
Andreas (Kusalananda) Kähäri
SciLifeLab, NBIS, ICM
Uppsala University, Sweden
.