很多人可能已经看到了允许你在需要root权限的文件上写的命令,即使你忘了用sudo打开vim:
:w !sudo tee %
Run Code Online (Sandbox Code Playgroud)
问题是我不知道这里到底发生了什么.
我已经想到了这个:
w是为了这个
*:w_c* *:write_c*
:[range]w[rite] [++opt] !{cmd}
Execute {cmd} with [range] lines as standard input
(note the space in front of the '!'). {cmd} is
executed like with ":!{cmd}", any '!' is replaced with
the previous command |:!|.
Run Code Online (Sandbox Code Playgroud)
所以它将所有行作为标准输入传递.
该!sudo tee部件tee使用管理员权限调用.
为了让所有人有意义,%应输出文件名(作为参数tee),但我找不到有关此行为的帮助的参考.
tl; dr有人可以帮我剖析这个命令吗?