Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sed] did not replace correctly #225

Open
sntran opened this issue Aug 1, 2024 · 2 comments
Open

[sed] did not replace correctly #225

sntran opened this issue Aug 1, 2024 · 2 comments

Comments

@sntran
Copy link

sntran commented Aug 1, 2024

With the following test.file:

[&_*]:foobar
"[&_*]:foobar"

With actual sed on macOS:

$ sed 's/\[\([^\&]*\)\&/\[\1\&/g' test.file
[&_*]:foobar
"[&_*]:foobar"

With shx sed:

npx shx sed 's/\[\([^\&]*\)\&/\[\1\&/g' test.txt                             
[&_*]:foobar
"[&_*]:foobar"

Node version: v20.12.2

@sntran
Copy link
Author

sntran commented Aug 1, 2024

After reading shelljs doc on sed, the replacement must be a JS replacement string, i.e. shx sed 's/\[([^\&]*)\&/[$1&/g'.

So in term of being a wrapper around shelljs, this is not a bug in shx.

However, being a shell replacement for sed, it is a surprised, as I would expect the same syntax as sed.

Also, in sed, open and close parentheses need to be escaped I believe, but not with shx.

@nfischer
Copy link
Member

Thanks for the report. Getting shx sed to be 100% compatible has been a challenge. I'd be willing to accept a contribution to the shx project if you're interested in working on this.

How does the current behavior compare to sed -e ... (extended regex syntax)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants