0

I am trying to do the following thing using the sed

 cp src/config/template.js src/config/index.js

export API_GATEWAY_ENDPOINT="http://localhost:9000/"

sed -i "" "s|{{API_GATEWAY_ENDPOINT}}|$API_GATEWAY_ENDPOINT|g" src/config/index.js

But when I run this script, then I am getting this error,

sed: can't read s|{{API_GATEWAY_ENDPOINT}}|http://localhost:9000/|g: No such file or directory

I am using a Linux machine.

Can any tell me why this is happening?

Omid Nikrah
  • 2,444
  • 3
  • 15
  • 30
ganesh kaspate
  • 1
  • 9
  • 41
  • 88

1 Answers1

0

The first argument to sed should be the script. So when you have that extra "", the second argument is interpreted as a file name.

And you don't need to copy the file and then do an inplace replacement. Instead use > operator to redirect the output from sed to the proper file.

>src/config/index.js <src/config/template.js sed "s|{{API_GATEWAY_ENDPOINT}}|$API_GATEWAY_ENDPOINT|g"
Håken Lid
  • 22,318
  • 9
  • 52
  • 67