Sujet : Re: Useless Use Of Regexes
De : ldo (at) *nospam* nz.invalid (Lawrence D'Oliveiro)
Groupes : comp.os.linux.miscDate : 28. Mar 2025, 21:25:19
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vs70je$3gfnr$3@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
User-Agent : Pan/0.162 (Pokrosvk)
On Fri, 28 Mar 2025 12:21:20 +0100, marrgol wrote:
On 2025-03-27 at 22:05 Lawrence D'Oliveiro wrote:
>
On Thu, 27 Mar 2025 16:51:16 +0100, Marc Haber wrote:
>
Lawrence D'Oliveiro <ldo@nz.invalid> wrote:
>
On Thu, 27 Mar 2025 07:58:32 +0100, Marc Haber wrote:
>
You could have it easier with getopt ...
>
Last I checked, getopt doesn’t do long options.
>
You should check again.
ldo@theon:~> help getopt getopts: getopts optstring name [arg ...]
[…]
You're quoting help to 'getopts' shell built-in command --
you are mistaking it for 'getopt' program from util-linux.
I had a look at that, too. Here’s an extract from the example script
/usr/share/doc/util-linux/examples/getopt-example.bash demonstrating
the use of the getopt(1) command from util-linux:
----
TEMP=$(getopt -o 'ab:c::' --long 'a-long,b-long:,c-long::' -n 'example.bash' -- "$@")
if [ $? -ne 0 ]; then
echo 'Terminating...' >&2
exit 1
fi
# Note the quotes around "$TEMP": they are essential!
eval set -- "$TEMP"
unset TEMP
while true; do
case "$1" in
'-a'|'--a-long')
echo 'Option a'
shift
continue
;;
'-b'|'--b-long')
echo "Option b, argument '$2'"
shift 2
continue
;;
'-c'|'--c-long')
# c has an optional argument. As we are in quoted mode,
# an empty parameter will be generated if its optional
# argument is not found.
case "$2" in
'')
echo 'Option c, no argument'
;;
*)
echo "Option c, argument '$2'"
;;
esac
shift 2
continue
;;
'--')
shift
break
;;
*)
echo 'Internal error!' >&2
exit 1
;;
esac
done
----
Doesn’t seem to me that’s saving much effort. Does it look like a
saving of effort to you?