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: no files given #169

Closed
viT-1 opened this issue Nov 28, 2019 · 8 comments · Fixed by #170
Closed

sed: no files given #169

viT-1 opened this issue Nov 28, 2019 · 8 comments · Fixed by #170

Comments

@viT-1
Copy link

viT-1 commented Nov 28, 2019

can't npm run resolvevue

package.json:

"scripts": {
...
"resolvevue": "shx sed -i \"s/'vue'/'https://cdn.jsdelivr.net/npm/vue@2.6.10/dist/vue.esm.browser.js'/g\" dist/*.js"
}
@viT-1
Copy link
Author

viT-1 commented Nov 28, 2019

Same issue but not my variant #165

@nfischer
Copy link
Member

nfischer commented Dec 4, 2019

This looks like a dupe of #165. Single quotes don't work the same on Windows. Please ping this thread if I've misunderstood.

@viT-1
Copy link
Author

viT-1 commented Dec 5, 2019

@nfischer No, I'm searching text contains single quotes.

@nfischer nfischer reopened this Dec 6, 2019
@nfischer
Copy link
Member

nfischer commented Dec 6, 2019

At a glance, your code looks like it should work in that case (although I'm not sure if dist/*.js needs to be dist\*.js on Windows).

Which OS did you try this on?

@viT-1
Copy link
Author

viT-1 commented Dec 6, 2019

@nfischer Yeah, I'm trying on Windows. Tried simple change 'foo' to 'bar', dist\*.js path is correct.

@nfischer
Copy link
Member

nfischer commented Dec 9, 2019

I think you need to escape the / characters in your replacement string, otherwise sed treats them as special delimiters. This behavior is consistent with unix sed:

# Failing to escape quotes in unix sed would fail like so:
sed -i "s/'vue'/'https://cccdn.jsdelivr.net/npm/vue@2.6.10/dist/vue.esm.browser.js'/g" dist/*.js
sed: -e expression #1, char 17: unknown option to `s'

You should escape the characters with a "" in the commandline like so:

# Escape '/' characters so sed doesn't treat them specially anymore:
shx sed -i "s/'vue'/'https:\/\/cdn.jsdelivr.net\/npm\/vue@2.6.10\/dist\/vue.esm.browser.js'/g" dist/*.js

# The same is necessary for unix sed:
sed -i "s/'vue'/'https:\/\/cdn.jsdelivr.net\/npm\/vue@2.6.10\/dist\/vue.esm.browser.js'/g" dist/*.js

To use this in a package.json, you need double \ so JSON passes a single \ onto shx:

{
  "scripts": {
    "resolvevue": "shx sed -i \"s/'vue'/'https:\\/\\/cdn.jsdelivr.net\\/npm\\/vue@2.6.10\\/dist\\/vue.esm.browser.js'/g\" dist/*.js"
  }
}

@nfischer
Copy link
Member

nfischer commented Dec 9, 2019

Updating labels. I don't think this is Win-specific, and it's clear this is not really a duplicate of issue #165 despite the similar error message.

@viT-1
Copy link
Author

viT-1 commented Dec 9, 2019

Yes! This (in package.json) works:

shx sed -i \"s/'vue'/'https:\\/\\/cdn.jsdelivr.net\\/npm\\/vue@2.6.10\\/dist\\/vue.esm.browser.js'/g\" dist/*.js

@nfischer Please, add this to documentation.

@viT-1 viT-1 closed this as completed Dec 9, 2019
@nfischer nfischer added the docs label Dec 9, 2019
nfischer added a commit that referenced this issue Dec 9, 2019
No change to logic, only docs.

This documents the special sed syntax (ex. `shx sed s/foo/bar/g
filename.txt`). With that, this mentions that `/` is a special
character, so the user must escape that if it's present in either the
regex or replacement string.

This also documents how Windows handles single quotes differently, so
it's desirable to avoid single quotes in package.json scripts. This part
isn't specific to sed, but since it's popular to quote sed expressions,
I'm adding this to the docs at the same time.

Fixes #165
Fixes #169
nfischer added a commit that referenced this issue Dec 9, 2019
No change to logic, only docs.

This documents the special sed syntax (ex. `shx sed s/foo/bar/g
filename.txt`). With that, this mentions that `/` is a special
character, so the user must escape that if it's present in either the
regex or replacement string.

This also documents how Windows handles single quotes differently, so
it's desirable to avoid single quotes in package.json scripts. This part
isn't specific to sed, but since it's popular to quote sed expressions,
I'm adding this to the docs at the same time.

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

Successfully merging a pull request may close this issue.

2 participants