what is meaning of following command?
sed -e 's|PATH="\(.*\)"|PATH="/opt/man/common/bin:\1"|g' -i /etc/environment
CodePudding user response:
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|
substitutesstring1
withstring2
- the delimiter (in this case
|
) is defined by the character following the substitute command (s
). More common is/
. - the flag
g
at the end tellssed
to substitute all non-overlapping matches (and not only the first one) - the
\(
and\)
define a group (in this case everything between the quotes) - the
\1
is a back-reference to the first group
- the delimiter (in this case
-i
is tellingsed
to apply the changes directly in the file (inline) instead of writing to standard output.