[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 2/3] dfa: new option DFA_STRAY_BACKSLASH_WARN
From: |
Bruno Haible |
Subject: |
Re: [PATCH 2/3] dfa: new option DFA_STRAY_BACKSLASH_WARN |
Date: |
Sat, 04 Jun 2022 05:18:59 +0200 |
Paul Eggert wrote:
> This is for grep, which wants to warn about stray backslashes that
> lead to unspecified behavior. For example, "grep -oi '\a'"
> surprisingly is not equivalent to "grep -oi 'a'", so the stray
> backslash should be warned about.
This warning punishes a traditional habit, namely to backslash-escape
a leading ASCII '-' character, so as to avoid it from being interpreted
as an option.
Suppose I want to search for an ASCII arrow in some text:
$ echo xy | ./grep '->'
./grep: invalid option -- '>'
Usage: grep [OPTION]... PATTERNS [FILE]...
Try 'grep --help' for more information.
Decades ago, I was taught that the workaround is to add a backslash.
This now produces
$ echo xy | ./grep '\->'
./grep: warning: stray \ before -
To avoid the warning, now I would have to write:
$ echo xy | ./grep '[-]>'
This is more cumbersome, because I have to insert two characters at
different positions, rather than just one character.
Bruno
- Re: [PATCH 2/3] dfa: new option DFA_STRAY_BACKSLASH_WARN,
Bruno Haible <=
- Re: [PATCH 2/3] dfa: new option DFA_STRAY_BACKSLASH_WARN, Paul Eggert, 2022/06/04
- Re: [PATCH 2/3] dfa: new option DFA_STRAY_BACKSLASH_WARN, Bruno Haible, 2022/06/04
- Re: [PATCH 2/3] dfa: new option DFA_STRAY_BACKSLASH_WARN, Paul Eggert, 2022/06/05
- Re: [PATCH 2/3] dfa: new option DFA_STRAY_BACKSLASH_WARN, Jim Meyering, 2022/06/06
- Re: [PATCH 2/3] dfa: new option DFA_STRAY_BACKSLASH_WARN, Paul Eggert, 2022/06/06
- Re: [PATCH 2/3] dfa: new option DFA_STRAY_BACKSLASH_WARN, Jim Meyering, 2022/06/23
- Re: [PATCH 2/3] dfa: new option DFA_STRAY_BACKSLASH_WARN, Paul Eggert, 2022/06/24