How can I `alias sudo !!`?

!! is expanded by bash when you type it. It's not expanded by alias substitution.

You can use the history built-in to do the expansion:

alias sbb='sudo $(history -p !!)'

If the command is more than a simple command (e.g. it contains redirections or pipes), you need to invoke a shell under sudo:

alias sbb='sudo "$BASH" -c "$(history -p !!)"'

Try:

alias sbb='sudo $(fc -ln -1)'

I like actually prefer to name it 'please':

alias please='sudo $(fc -ln -1)'

Info: fc is a in-built command in the bash shell. that lists, edits and reexecutes commands previously entered to an interactive shell.


Now there's a repository for this purpose in GitHub, it magically checks whether it needs superuser rights, also fixes the typos:

https://github.com/nvbn/thefuck