summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2022-06-05 10:42:22 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2022-06-06 14:51:47 -0700
commit6f52ef30e5634b1104b372c266ca8cc80b451c7d (patch)
treec6a2dbe46d75b333e2c0226937979a0a907684f3 /src
parent739892e8d4461a8246fa4c6a0ece18a14ce1e51b (diff)
downloadgrep-6f52ef30e5634b1104b372c266ca8cc80b451c7d.tar.gz
grep: don’t diagnose "grep '\-c'"
* src/grep.c (main): Skip past leading backslash of a pattern that begins with "\-". Inspired by a remark by Bruno Haible in: https://lists.gnu.org/r/bug-gnulib/2022-06/msg00022.html
Diffstat (limited to 'src')
-rw-r--r--src/grep.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/grep.c b/src/grep.c
index 59d34310..9b9407d6 100644
--- a/src/grep.c
+++ b/src/grep.c
@@ -2848,8 +2848,16 @@ main (int argc, char **argv)
}
else if (optind < argc)
{
+ /* If a command-line regular expression operand starts with '\-',
+ skip the '\'. This suppresses a stray-backslash warning if a
+ script uses the non-POSIX "grep '\-x'" to avoid treating
+ '-x' as an option. */
+ char const *pat = argv[optind++];
+ bool skip_bs = (matcher != F_MATCHER_INDEX
+ && pat[0] == '\\' && pat[1] == '-');
+
/* Make a copy so that it can be reallocated or freed later. */
- pattern_array = keys = xstrdup (argv[optind++]);
+ pattern_array = keys = xstrdup (pat + skip_bs);
idx_t patlen = strlen (keys);
keys[patlen] = '\n';
keycc = update_patterns (keys, 0, patlen + 1, "");