[BUG] 'find' does not support '--'
Eli Schwartz
eschwartz at archlinux.org
Wed Dec 19 20:24:55 UTC 2018
On 12/19/18 1:49 PM, Martijn Dekker wrote:
> Busybox 'find' does not support '--' to signal end of options, as POSIX
> requires[*]. (This is the standard way of allowing arguments, in this
> case path names, starting with a dash.)
>
> $ ./usr/bin/find -- /dev/null -print
> find: unrecognized: --
> [long usage message omitted]
>
> Thanks,
>
> - M.
>
> [*] References:
>
> http://pubs.opengroup.org/onlinepubs/9699919799/utilities/find.html
> "The find utility shall conform to XBD Utility Syntax Guidelines ."
>
> http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html#tag_12_02
>
> "Guideline 10: The first -- argument that is not an option-argument
> should be accepted as a delimiter indicating the end of options. Any
> following arguments should be treated as operands, even if they begin
> with the '-' character."
Have you tried with other find implementations? In order to be fair, you
should use a filename starting with the "-" you intend to use.
Comparing GNU `/usr/bin/find` vs `/usr/bin/busybox find`
$ touch -- -foo
$ find -- -foo -print
find: unknown predicate `-foo'
$ busybox find -- -foo -print
find: unrecognized: --
BusyBox v1.29.3 () multi-call binary.
[...]
$ find -- ./-foo -print
./-foo
GNU find is correctly treating -- as end-of-options, and then
interpreting all following members of argv as (according to the POSIX
specification):
"The first operand and subsequent operands up to but not including the
first operand that starts with a '-', or is a '!' or a '(', shall be
interpreted as path operands."
One could argue that Busybox find is incorrect for erroring on -- as
unknown, but on the other hand, the only thing it allows you to do is
recognize the *options* "-H" and "-L" as *operands* instead.
Both of which are invalid as operands, since the fact that they begin
with a dash, means that find categorizes them as *expression operands*
(GNU find names this a predicate), not *pathname operands*, and they are
not valid expressions.
I don't know what your desired end goal is. How would implementing --
help you out?
- Either way you are not permitted to use pathname operands that start
with a dash.
- Either way the command will abort with an error.
The correct way to play this game is to never use -- with find. Its only
POSIX-defined purpose is to be silently ignored.
If you want to use pathname operands that begin with a dash, you must
check to see if the first character is a "/" and if not, prepend "./" to it.
--
Eli Schwartz
Bug Wrangler and Trusted User
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 1601 bytes
Desc: OpenPGP digital signature
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20181219/be8ab0bf/attachment.asc>
More information about the busybox
mailing list