user2439278
user2439278

Reputation: 1224

Replace variable value in javascript using sed command

I have one variable in app.js called

process.env.NODE_ENV = 'development';

i tried sed command to replace the value from development to production.

sed -i -e "s/process.env.NODE_ENV = \'development\';/process.env.NODE_ENV = \'production\';/g" app.js

But it didnt work. How to change the value in app.js file.

Upvotes: 1

Views: 1567

Answers (1)

visit1985
visit1985

Reputation: 498

As you use double quotes, the backslashes get interpreted by your shell. You can see that with set -x. The interpreted command which is called looks like:

sed -i -e 's/process.env.NODE_ENV = \'\''development\'\'';/process.env.NODE_ENV = \'\''production\'\'';/g' app.js

If you remove the backslashes, it works.

Upvotes: 1

Related Questions