summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAssaf Gordon <assafgordon@gmail.com>2017-08-16 14:09:17 -0600
committerBernhard Voelker <mail@bernhard-voelker.de>2017-08-17 08:14:52 +0200
commit9530e31f6d4febf8ff08f931f70b40d41603ef8d (patch)
treec98f122d92e7bbad9b233f4336c1d8f217bc51bc
parent50a7c5d1f572d50d6c9d43d04e9c9fd55d66b466 (diff)
downloadfindutils-9530e31f6d4febf8ff08f931f70b40d41603ef8d.tar.gz
find: give helpful hint for unquoted patterns errors
Try to detect cases where the user provided an unquoted shell-glob pattern (which was expanded by the shell before calling find(1), resulting in an invalid usage). $ touch a.txt b.txt c.txt $ find -name *.txt find: paths must precede expression: `b.txt' find: possible unquoted pattern after predicate `-name'? Continuation of https://savannah.gnu.org/bugs/?51711 https://lists.gnu.org/archive/html/bug-findutils/2017-08/msg00000.html https://git.sv.gnu.org/cgit/findutils.git/commit/?id=50a7c5d1f572 * find/tree.c (build_expression_tree): If the offending argument is an existing file, print a hint with the last (valid) predicate.
-rw-r--r--find/tree.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/find/tree.c b/find/tree.c
index ee466ea6..cc7772d2 100644
--- a/find/tree.c
+++ b/find/tree.c
@@ -1275,7 +1275,13 @@ 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 (EXIT_FAILURE, 0, _("paths must precede expression: `%s'"), argv[i]);
+ {
+ error (0, 0, _("paths must precede expression: `%s'"), argv[i]);
+ if (access(argv[i], F_OK)==0)
+ error (0, 0, _("possible unquoted pattern after predicate `%s'?"),
+ last_pred->p_name);
+ exit (EXIT_FAILURE);
+ }
predicate_name = argv[i];
parse_entry = find_parser (predicate_name);