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,307
  • 3
  • 12
  • 27
ganesh kaspate
  • 777
  • 1
  • 12
  • 25

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
  • 21,116
  • 9
  • 46
  • 63