9fans / plan9port

Plan 9 from User Space
https://9fans.github.io/plan9port/
Other
1.62k stars 320 forks source link

awk: need to escape regexp delimiter (/) inside square brackets in a regexp leads to unportable code #537

Open phillbush opened 2 years ago

phillbush commented 2 years ago

Plan9port's awk needs the regexp delimiter / to be escaped even when between square brackets in a regexp.
AFAIU, except for the hyphen, characters between square brackets in a regexp need not to be escaped, as they are taken literally. However, in p9p awk, the regexp delimiter character, the slash /, needs to be escaped in that context.

In the image, I compare the following command in GNU awk, mawk, OpenBSD awk and Plan9port awk.
It works in all awk implementations, except in p9p's.

awk 'BEGIN {s = "/"; sub(/[/]/, "a", s); print s}'

awk