On 08/10/2017 01:12 AM, anonymous wrote:
> akraum@akraumGI ~/Downloads $ ls
> 2017-07-29_Entwurf-Berichtsteil-Lebensstile.pdf
> Ant Videos
> blockadesw.jpg
> blockbunt.jpg
> DSC1316.jpg
> faustklein.JPG
> fax.pdf
> notanugget.jpg
> todktter1.jpg
> todktter2.jpg
> Widerstand-gegen-Wiesenhof-Part-1.pdf
>
> akraum@akraumGI ~/Downloads $ LANG=C find . -name fax* bloc*
> find: paths must precede expression: blockadesw.jpg
> Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec]
> [path...] [expression]
> 
> This was, what I got by typing two patterns into find-command.

Sorry to say, but actually you did not pass 2 patterns to find.
Instead, you rather passed the 2 patterns to the shell which
globbed the file names before passing them to find(1).

With the above content of the directory (which is presumably
the output of 'ls -1' instead of the shown 'ls'), the shell
passed 3 arguments after the -name option; this can easily be
demonstrated by prepending the command line with 'echo':

  $ echo find . -name fax* block*
  find . -name fax.pdf blockadesw.jpg blockbunt.jpg
  ...

And find told you the offending part.

I have to admit that the file name is a little lost in the error
diagnostic.  IMO the file name should be quoted, and the "Usage"
text should be omitted.  With this, the actual error would be
more prominent:

  $ find . -name fax* block*
  find: paths must precede expression: `blockadesw.jpg'

The attached fixes it.  Comments?

Have a nice day,
Berny
>From 50a7c5d1f572d50d6c9d43d04e9c9fd55d66b466 Mon Sep 17 00:00:00 2001
From: Bernhard Voelker <m...@bernhard-voelker.de>
Date: Thu, 10 Aug 2017 08:45:56 +0200
Subject: [PATCH] find: avoid usage() in more error cases

When the user passes a bad command line, then find(1) outputs the
error message followed by a short usage() text, e.g. (wrapped):

  $ find . -name a* b*
  find: paths must precede expression: bfile
  Usage: find [-H] [-L] [-P] [-Olevel] \
  [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]

Omit the usage() text in more cases like this in order to make the
error diagnostic more eye-catching.

* find/tree.c (build_expression_tree): Exit with EXIT_FAILURE
immediately in more cases, i.e., without outputting also a short
usage() text.  While at it, add quotes around the offending argument
in one another place.
* NEWS (Improvements): Mention the fix.

Reported in https://savannah.gnu.org/bugs/?51711
---
 NEWS        |  3 +++
 find/tree.c | 17 +++++------------
 2 files changed, 8 insertions(+), 12 deletions(-)

diff --git a/NEWS b/NEWS
index 2f263aa..61269c1 100644
--- a/NEWS
+++ b/NEWS
@@ -35,6 +35,9 @@ of the - yet more portable - '( -type l -o -type d )'.
 find now diagnoses failures returned by readdir().  This bug was inherent
 in the use of FTS.
 
+find now exits in more cases immediately after the error diagnostic, i.e.,
+without the following usage text, to make the former more eye-catching.
+
 xargs now supports the -o, --open-tty option to reopen stdin as /dev/tty
 in the child process before executing the command; useful to run an
 interactive application.  Added for compatibility with BSD.
diff --git a/find/tree.c b/find/tree.c
index 2bbfbe5..ee466ea 100644
--- a/find/tree.c
+++ b/find/tree.c
@@ -1275,18 +1275,14 @@ build_expression_tree (int argc, char *argv[], int end_of_leading_options)
     {
       state.already_issued_stat_error_msg = false;
       if (!looks_like_expression (argv[i], false))
-	{
-	  error (0, 0, _("paths must precede expression: %s"), argv[i]);
-	  usage (EXIT_FAILURE);
-	}
+	error (EXIT_FAILURE, 0, _("paths must precede expression: `%s'"), argv[i]);
 
       predicate_name = argv[i];
       parse_entry = find_parser (predicate_name);
       if (parse_entry == NULL)
 	{
 	  /* Command line option not recognized */
-	  error (0, 0, _("unknown predicate `%s'"), predicate_name);
-	  usage (EXIT_FAILURE);
+	  error (EXIT_FAILURE, 0, _("unknown predicate `%s'"), predicate_name);
 	}
 
       /* We have recognised a test of the form -foo.  Eat that,
@@ -1306,21 +1302,18 @@ build_expression_tree (int argc, char *argv[], int end_of_leading_options)
 		  /* The special parse function spat out the
 		   * predicate.  It must be invalid, or not tasty.
 		   */
-		  error (0, 0, _("invalid predicate `%s'"), predicate_name);
-		  usage (EXIT_FAILURE);
+		  error (EXIT_FAILURE, 0, _("invalid predicate `%s'"), predicate_name);
 		}
 	      else
 		{
-		  error (0, 0, _("invalid argument `%s' to `%s'"),
+		  error (EXIT_FAILURE, 0, _("invalid argument `%s' to `%s'"),
 			 argv[i], predicate_name);
-		  usage (EXIT_FAILURE);
 		}
 	    }
 	  else
 	    {
 	      /* Command line option requires an argument */
-	      error (0, 0, _("missing argument to `%s'"), predicate_name);
-	      usage (EXIT_FAILURE);
+	      error (EXIT_FAILURE, 0, _("missing argument to `%s'"), predicate_name);
 	    }
 	}
       else
-- 
2.1.4

_______________________________________________
Findutils-patches mailing list
Findutils-patches@gnu.org
https://lists.gnu.org/mailman/listinfo/findutils-patches

Reply via email to