shelljs / shx

Portable Shell Commands for Node
MIT License
1.72k stars 44 forks source link

[sed] did not replace correctly #225

Open sntran opened 1 month ago

sntran commented 1 month ago

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 commented 1 month ago

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.