1

my npm script needs to run sed to replace some string, e.g.

"prebuild":"sed 's/http:\/\/example.com/https:\/\/something_real.com/' < static/config.js.example > static/config.js",

"build": "node build/build.js"

But the backsplash escapes are interpreted by shell when run npm run build, so I got the error,

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'

So how do I prevent shell from doing that ?

Qiulang
  • 10,295
  • 11
  • 80
  • 129
  • 1
    I think why `\/` didn't work here may be because it is inside double quotes and therefore you need `\\/` , using different delimiter is better.. also, you would need to escape `.` in search portion of substitute command, as it is a metacharacter – Sundeep Jan 21 '19 at 06:09

1 Answers1

3

You can use a different character as delimiter

sed 's@http://example.com@https://something_real.com@' < static/config.js.example > static/config.js
Diego Torres Milano
  • 65,697
  • 9
  • 111
  • 134