help-bash
[Top][All Lists]
Advanced

[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 01:42:54 +0200

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

Regards,

-- 
Andreas (Kusalananda) Kähäri
SciLifeLab, NBIS, ICM
Uppsala University, Sweden

.



reply via email to

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