问题原文
原帖链接 · thermans · CC BY-SA 4.0
I run a command, then realize it should have been run with sudo.
In zsh I have a function so that I can hit a ^x^x and it will grab the previous line from the history and prepend sudo to it, so I can run it again.
Is it possible to do this with bash?
已采纳解答
原帖链接 · trueCamelType · CC BY-SA 4.0
As mentioned by Gerald Schneider, this is a duplicate that exists on Stack Overflow, but since it doesn't exist on Serverfault, and it won't let me mark it as duplicate, I'll just put the answer here as well.
From jm666 question here
You can write:
sudo !!
(See §9.3 "History Expansion" in the Bash Reference Manual.)
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
