多么“须藤!!” 在 bash 中工作:
$ touch /bin/1
touch: cannot touch `/bin/1': Permission denied
$ sudo !!
sudo touch /bin/1
Run Code Online (Sandbox Code Playgroud)
oos*_*hro 12
bash 支持历史扩展功能。历史扩展由“!”实现。'!!' 参考上一条命令。
历史扩展在读取命令行后立即执行,在 execve() 系统调用之前。
$ touch /bin/1
touch: ?????????? ????????? touch ??? «/bin/1»: ???????? ? ???????
$ sudo strace !!
sudo strace touch /bin/1
execve("/usr/bin/touch", ["touch", "/bin/1"], [/* 17 vars */]) = 0
Run Code Online (Sandbox Code Playgroud)
bash 扩展“sudo !!” 到“sudo touch /bin/1”然后运行命令。