使用sed命令替换javascript中的变量值

时间:2021-02-26 16:51:48

I have one variable in app.js called

我在app.js中有一个变量叫做

process.env.NODE_ENV = 'development';

process.env.NODE_ENV ='development';

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

我尝试使用sed命令将值从开发替换为生产。

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.

但它没有用。如何更改app.js文件中的值。

1 个解决方案

#1


0  

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:

当您使用双引号时,反斜杠会被shell解释。您可以使用set -x查看。调用的解释命令如下所示:

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

If you remove the backslashes, it works.

如果你删除反斜杠,它的工作原理。

#1


0  

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:

当您使用双引号时,反斜杠会被shell解释。您可以使用set -x查看。调用的解释命令如下所示:

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

If you remove the backslashes, it works.

如果你删除反斜杠,它的工作原理。