I'm appalled. Setting

alias please='sudo !!'

returns with

sudo: !!: command not found

rather than doing what sudo !! does. How do I make this work?

· · Web · 3 · 0 · 2

@unused0 alias please='sudo $(fc -ln -1)' seems to do the trick! :)

For reasons that have never made sense to me, "!!" isn't expanded when used in a Bash alias. You have to use 'history' instead.

The simplest solution is something like:
alias please='sudo $(history -p !!)'

This SE thread has some caveats and other approaches:

Sign in to participate in the conversation
Mastodon @ SDF

"I appreciate SDF but it's a general-purpose server and the name doesn't make it obvious that it's about art." - Eugen Rochko