[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug-gawk] escaping open curly bracket produces unexpected warning with
From: |
Ed Morton |
Subject: |
[bug-gawk] escaping open curly bracket produces unexpected warning with --posix |
Date: |
Wed, 19 Jun 2019 07:56:16 -0500 |
User-agent: |
Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.7.1 |
I just came across this in gawk 5.0.0 (note "4"):
1) $ echo 'foo{bar' | awk '/{/'
foo{bar
2) $ echo 'foo{bar' | awk --posix '/{/'
awk: cmd. line:1: error: Invalid preceding regular expression: /{/
3) $ echo 'foo{bar' | awk '/\{/'
foo{bar
4) $ echo 'foo{bar' | awk --posix '/\{/'
awk: cmd. line:1: warning: regexp escape sequence `\{' is not a
known regexp operator
foo{bar
I understand 1, 2, and 3 but I don't understand why I get the warning
from 4 above. I expected `\{` to simply be treated as a literal `{` with
no warnings just like other RE metachars are:
$ echo 'foo[bar' | awk --posix '/\[/'
foo[bar
$ echo 'foo+bar' | awk --posix '/\+/'
foo+bar
Instead I had to put it inside square brackets to get it treated as
literal with no warnings:
$ echo 'foo{bar' | awk --posix '/[{]/'
foo{bar
as no amount of additional preceding backslashes would make it "work"
without a warning:
$ echo 'foo{bar' | awk --posix '/\{/'
awk: cmd. line:1: warning: regexp escape sequence `\{' is not a
known regexp operator
foo{bar
$ echo 'foo{bar' | awk --posix '/\\{/'
$ echo 'foo{bar' | awk --posix '/\\\{/'
awk: cmd. line:1: warning: regexp escape sequence `\{' is not a
known regexp operator
$ echo 'foo{bar' | awk --posix '/\\\\{/'
$
Regards,
Ed.
- [bug-gawk] escaping open curly bracket produces unexpected warning with --posix,
Ed Morton <=