[英]what is meaning of sed -e 's|PATH="\(.*\)"|PATH="/opt/man/common/bin:\1"|g' -i /etc/environment line
以下命令是什么意思?
sed -e 's|PATH="\(.*\)"|PATH="/opt/man/common/bin:\1"|g' -i /etc/environment
It substitutes all the instances of它替换了所有的实例
PATH="somestring"
with和
PATH="/opt/man/common/bin:somestring"
in the file /etc/environment
在文件/etc/environment
In detail详细地
s|string1|string2|
substitutes string1
with string2
用string2
替换string1
|
) is defined by the character following the substitute command ( s
).分隔符(在本例中为|
)由替换命令 ( s
) 后面的字符定义。 More common is /
.更常见的是/
。g
at the end tells sed
to substitute all non-overlapping matches (and not only the first one)最后的标志g
告诉sed
替换所有不重叠的匹配项(而不仅仅是第一个匹配项)\(
and \)
define a group (in this case everything between the quotes) \(
和\)
定义一个组(在这种情况下,引号之间的所有内容)\1
is a back-reference to the first group \1
是对第一组的反向引用-i
is telling sed
to apply the changes directly in the file (inline) instead of writing to standard output. -i
告诉sed
直接在文件中应用更改(内联),而不是写入标准输出。Edit编辑
As pointed out in the comments this regular expression is very fragile.正如评论中指出的那样,这个正则表达式非常脆弱。
CDPATH="string"
例如,它将匹配CDPATH="string"
'
.它不会匹配由'
分隔的字符串。 It will not match PATH='somepath'
.它不会匹配PATH='somepath'
。# some comment with PATH="" in the text
例如# some comment with PATH="" in the text
STRING='PATH="somepath"
它将匹配其他字符串,例如STRING='PATH="somepath"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.