sudo alias

bash

>What

Add a sudo alias to your shell:

# in your .bashrc or similar setup script
alias sudo='sudo '

>Why

So you can run any alias with sudo.

>Explanation

The magic is in the blank line at the end of the alias which makes the shell check if the word after “sudo” is also an alias, and then expands it.

>Reference

The Bash manual’s section on aliases: https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Aliases

Aliases allow a string to be substituted for a word when it is used as the first word of a simple command. […] If the last character of the alias value is a blank, then the next command word following the alias is also checked for alias expansion.

>Found

  1. When looking at Z-shell plugins and comparing zsh versus fish.
  2. Linked to his dotfiles where I found the strange alias.
  3. That I duckduckgo:ed up to have a nice explanation that referred to the Bash manual.