Could someone explain this command for me:
cat | sed -e 's,%,$,g' | sudo tee /etc/init.d/dropbox << EOF
echo "Hello World"
EOF
What does the "sed" command do?
sed
is the Stream EDitor . It can do a whole pile of really cool things , but the most common is text replacement.
The s,%,$,g
part of the command line is the sed
command to execute. The s
stands for substitute, the ,
characters are delimiters (other characters can be used; /
, :
and @
are popular). The %
is the pattern to match (here a literal percent sign) and the $
is the second pattern to match (here a literal dollar sign). The g
at the end means to g
lobally replace on each line (otherwise it would only update the first match).
Here sed
is replacing all occurrences of %
with $
in its standard input.
As an example
$ echo 'foo%bar%' | sed -e 's,%,$,g'
will produce "foo$bar$".
它读取Hello World
( cat
),用$
替换所有( g
) %
的出现,并且(over)以root身份将其写入/etc/init.d/dropbox
。
sed is a stream editor. I would say try man sed.If you didn't find this man page in your system refer this URL:
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.