Bug 263478 - awk: syntax error in regular expression $^
Summary: awk: syntax error in regular expression $^
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 13.0-RELEASE
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-04-23 00:41 UTC by Kevin Locke
Modified: 2022-08-21 07:31 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kevin Locke 2022-04-23 00:41:40 UTC
Using the regular expression $^ as a pattern, for example by running `awk /$^/`, causes the following error:

    awk: syntax error in regular expression $^ at 
     source line number 1
     context is
	     >>> /$^/ <<< 

As far as I can tell, $^ is a valid Extended Regular Expression,[^1] as expected by awk,[^2] although it is a bit unusual.

I encountered the bug in the ident[^3] script used by jscal-save of the Linux Console Project and am not aware of any uses likely to affect FreeBSD users.  Feel free to take it for what you will.

[^1]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html#tag_09_04
[^2]: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/awk.html#tag_20_06_13_04
[^3]: https://sourceforge.net/p/linuxconsole/code/ci/08ddbccfe470b346a8fc903386dea916be3a4e9f/tree/utils/ident
Comment 1 pprocacci 2022-08-21 07:31:21 UTC
The syntax you provided is syntactically correct, however the result of such a match is undefined.

An argument could be made that '$^' should parse without error, to which I actually agree as that follows the grammar as posted by you, but I don't see how '$^' is useful.

If it's working elsewhere, it's working within that 'undefined behavior' realm which could change the moment POSIX actually defines $^ as having an actual meaning.  As of right now, it doesn't.

Perhaps you could say, it means 'end of line' then 'newline' but that doesn't really make sense because you could anchor on either just a newline or end of line.

Those are my thoughts anyways.