Peter da Silva writes:

> There's nothing crazy about [-print] at all. It's not a flag, if it
> was a flag it would be a single character

Then there's things like like -maxdepth.  FreeBSD find doesn't include
it in the list of 'options', instead categorizing it as a 'primary', but
it carries this caveat:

  If any -maxdepth primary is specified, it applies to the entire
  expression even if it would not normally be evaluated. 

So it has the behaviour of an option, but the appearance of a term in
the expression.  In the circumstances it isn't surprising that some
people might get confused about the rules applying to other terms.

GNU find is different (of course).  It does classify -maxdepth as an
'option'.  But it isn't in the list of 'options' that find takes
(presumably that would be too simple); instead it sub-classifies the
'expressions' (that follow options in a find command) into 'tests',
'actions', and, um 'options'.  Meaning the manpage has two lists of
'options'.  Nice.

The introduction to expression-options suggests:

  ... for clarity, it is best to place them at the beginning of the
  expression.  A warning is issued  if you don't do this.

And indeed a warning is issued:

   $ find . -name '*.txt' -maxdepth 1
   find: warning: you have specified the -maxdepth option after a
   non-option argument -name, but options are not positional (-maxdepth
   affects tests specified before it as well as those specified after
   it). Please specify options before other arguments.

Hmmm, before "other arguments", eh?  That suggests putting it as the
very first argument -- let's try that:

   $ find -maxdepth 1 . -name '*.txt'
   find: paths must precede expression
   Usage: find [-H] [-L] [-P] [path...] [expression]

So even its own error messages get confused by this stuff!  Hate!

Smylers

Reply via email to