Bug 13051 - sed: the substitute command ignores the g flag if the supplied pattern starts with '^'
Summary: sed: the substitute command ignores the g flag if the supplied pattern starts...
Status: NEW
Alias: None
Product: Busybox
Classification: Unclassified
Component: Standard Compliance (show other bugs)
Version: 1.33.x
Hardware: All Linux
: P5 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-07-01 04:03 UTC by yvt
Modified: 2021-07-19 19:44 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description yvt 2020-07-01 04:03:23 UTC
$ sed --help
BusyBox v1.31.1 () multi-call binary.
[...]

The commit <https://git.busybox.net/busybox/commit/?id=f36635cec6da728fe06b849089ce2f6c1690dc67> introduced this behavior to address the bug with `echo "aah" | sed 's/^a/b/g'`. However, this breaks other regexs, such as:

$ echo 'a b c' | sed -E 's/^a|b|c/d/g'
d b c

Simply reordering the clauses so that '^' doesn't appear at the start makes it working as intended:

$ echo 'a b c' | sed -E 's/b|^a|c/d/g'
d d d
Comment 1 Al Mr 2021-07-19 19:44:18 UTC
I'm still seeing this in 1.33.1 and master. However, removing the (updated version of) the commit mentioned by the OP does not fix

echo 'a b c' | sed -E 's/^a|b|c/d/g'

... but neither does it break `echo "aah" | sed 's/^a/b/g'`