Closed. This question needs details or clarity。它当前不接受答案。
想改善这个问题吗?添加详细信息并通过editing this post阐明问题。
去年关闭。
在我的nginx配置文件中,有以下几行:
现在,我想以编程方式注释掉/取消注释这两行:
所以我想到了
https://stackoverflow.com/a/27355109
不幸的是我无法正常工作。逃逸字符可能存在问题。有人可以帮忙吗?
要取消注释,请使用以下命令:
想改善这个问题吗?添加详细信息并通过editing this post阐明问题。
去年关闭。
在我的nginx配置文件中,有以下几行:
location / {
try_files $uri $uri/ =404;
auth_basic "Restricted Content";
auth_basic_user_file /etc/nginx/.htpasswd;
}
现在,我想以编程方式注释掉/取消注释这两行:
auth_basic "Restricted Content";
auth_basic_user_file /etc/nginx/.htpasswd;
所以我想到了
sed
并在这里找到了这篇文章:https://stackoverflow.com/a/27355109
不幸的是我无法正常工作。逃逸字符可能存在问题。有人可以帮忙吗?
最佳答案
要注释掉这些行,请使用命令
sed \
-e 's|auth_basic "Restricted Content";|# \0|' \
-e 's|auth_basic_user_file /etc/nginx/.htpasswd;|# \0|' \
your_file
要取消注释,请使用以下命令:
sed \
-e 's|# \(auth_basic "Restricted Content";\)|\1|' \
-e 's|# \(auth_basic_user_file /etc/nginx/.htpasswd;\)|\1|' \
your_file
关于linux - 用sed注释掉/注释,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54280425/