【发布时间】:2019-01-21 05:42:22
【问题描述】:
我的 npm 脚本需要运行 sed 来替换一些字符串,例如
"prebuild":"sed 's/http:\/\/example.com/https:\/\/something_real.com/' < static/config.js.example > static/config.js",
"build": "node build/build.js"
但是运行npm run build时shell会解释反溅转义,所以我得到了错误,
qiulang$ npm run build
> sed 's/http://example.com/https://something_real/' < static/config.js.example > static/config.js
sed: 1: "s/http://emicall-cmb.em ...": bad flag in substitute command: 'e'
那么如何防止 shell 这样做呢?
【问题讨论】:
-
我认为为什么
\/在这里不起作用可能是因为它在双引号内,因此您需要\\/,使用不同的分隔符更好..另外,您需要转义 @ 987654326@ 在替换命令的搜索部分,因为它是一个元字符
标签: node.js bash shell npm sed