【发布时间】:2018-05-12 12:18:16
【问题描述】:
我一直在尝试找出如何替换 CSS 文件中包含的某些字符串,这些字符串包含我希望使用 Bash 一次在多个文件中替换的相同 CSS 变量字符串,以避免必须打开的繁琐任务在每个目录中添加每个 CSS 文件的实例,只是为了替换这些 CSS 文件中的某些字符串。
在我的 CSS 文件中,我想注释掉 CSS 代码中的某些行,但是我无法转义某些字符并将该行转换为注释掉的行,即; outline-style: dashed; 与 /*outline-style: dashed;*/
我不知道如何转义 : 和 ; 字符以及以下用于注释行 /* */ 到目前为止我尝试过但对我不起作用的是以下通过在 perl 中使用 xargs;
find . -type f | xargs perl -e 's/outline-style dashed;/\/*outline-style dashed;*/\/g;'
但这会返回一个错误提示
Backslash found where operator expected at -e line 1, near "s/outline-
style dashed;/\/*outline-style dashed;*/\"
syntax error at -e line 1, near "s/outline-style dashed;/\/*outline-
style dashed;*/\"
Search pattern not terminated at -e line 1.
xargs: perl: exited with status 255; aborting
我也尝试过使用 sed,这似乎适用于最简单的替换
find . -type f -exec sed -i 's/$^outline-style\: dotted\;/\/*outline-style\: dotted\;/g' *.{css} \;
但这并不完全有效,它只会返回错误消息sed: can't read *.{css}: No such file or directory
我尝试不在那里添加*.{css},但仍然给我同样的错误,但没有任何 CSS 文件的输出更改。
【问题讨论】:
标签: css bash shell sed scripting