以下命令是什么意思?
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
In detail
s|string1|string2|
substitutes string1
with string2
|
) is defined by the character following the substitute command ( s
). More common is /
.g
at the end tells sed
to substitute all non-overlapping matches (and not only the first one)\(
and \)
define a group (in this case everything between the quotes) \1
is a back-reference to the first group -i
is telling sed
to apply the changes directly in the file (inline) instead of writing to standard output. Edit
As pointed out in the comments this regular expression is very fragile.
CDPATH="string"
'
. It will not match PATH='somepath'
.# some comment with PATH="" in the text
STRING='PATH="somepath"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.