如何防止bash在npm脚本中转义反斜杠?

时间:2019-01-21 05:42:22

标签: node.js bash shell npm sed

我的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这么做呢?

1 个答案:

答案 0 :(得分:1)

您可以使用其他字符作为分隔符

sed 's@http://example.com@https://something_real.com@' < static/config.js.example > static/config.js