[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] Bash script supporting complex options like GNU find
From: |
Eric Blake |
Subject: |
Re: [Help-bash] Bash script supporting complex options like GNU find |
Date: |
Mon, 12 Feb 2018 09:24:23 -0600 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 |
On 02/12/2018 08:46 AM, Peng Yu wrote:
https://mywiki.wooledge.org/BashFAQ/035
The examples there cannot be readily extended to support '(' ')' '-a'
'-o' '!' as in GNU find. In fact, I doubt that getopt can support
them.
If you think otherwise, could you show an example how '(' ')' '-a'
'-o' '!' can be supported with getopt?
If you need inspiration on how to write an option parser that matches
find(1), then read the source code for find [1] for inspiration. Note
that it does not use getopt() for parsing the bulk of its command line,
but its own hand-rolled parser. And therefore, any reimplementation
will likewise have to use custom manual parsing rather than being able
to rely on getopt-like libraries.
[1] https://git.savannah.gnu.org/cgit/findutils.git/tree/find/parser.c
But your goal of re-writing find(1) in shell seems rather quixotic.
You're investing a lot of time into something that will never compete in
speed with the native C version, so about the only benefit you will get
from your efforts is a better appreciation of how shell programming
works (or does not work), and not something that anyone else would ever
want to use.
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org