Skip to content
No description or website provided.
Branch: master
Clone or download
Latest commit 2e09200 Oct 29, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
LICENSE First public release Oct 21, 2019 Better docs. Oct 22, 2019 Fix comment Oct 29, 2019


converts ALL_CAPS commands to sudo all_caps


Source (or stick it into your bashrc). Then when you type:

$ YUM -y update

It will be converted to:

$ sudo yum -y update

If you use this in your .bashrc you should probably reserve it for interactive shells, doing something along the lines of:

if [[ x$PS1 != x ]]; then


  • The present implementation is full of bash-isms and will likely not run on any other shell.

  • The code runs instead of any not-found command invoked as an all caps verb. (So /usr/bin/CAT is not affected, but CAT and /USR/BIN/CAT are.)

  • It runs as a command_not_found_handle by pre-chaininig itself to any preexisting handle, which gets renamed to command_not_found_handle_orig. So things like automatic search of installable commands, which on Fedora is implementaed as a not-found handler (and which I find terminally irritating, but still) keep working. Also, in the rare case where an all-caps command actually exists, real commands will not be obscured.

  • OTOH, this cute prechaining trick may fail spectacularly and in unforeseen ways if other parts of your .bashrc & co. are also playing tricks with said handle.

  • General Caveat emptor cautions apply.


From an original implementation seen on twitter (and HN?):

Alas, the original implementation is not particularly fast:

# Interesting, BUT...
# SUDO - shout at bash to su commands
# Distributed under GNU GPLv2, @jthistle on github

shopt -s expand_aliases

IFS=":" read -ra PATHS <<< "$PATH"

# OUCH! ... this is bound to take forever.
for i in "${PATHS[@]}"; do
	for j in $( ls "$i" ); do
		if [ ${j^^} != $j ] && [ $j != "sudo" ]; then
			alias ${j^^}="sudo $j"

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


# end SUDO

This prompted me to tweet along the lines of:

# this might be an alternative

function command_not_found_handle () {
    local allcaps=$(echo $1 | grep -E '^[A-Z0-9_-]+$')
    if [[ x$allcaps != x ]]; then
	   local cmd=$(echo $1 | tr A-Z a-z)
	   sudo $cmd "$@"
	   return 127

Which provoked a fruitful tweet exchange (which I did not know was at all possible) viz.

It's been sitting in my .bashrc for a few months, with no issues. I do not use it heavily though, because I do SU - a lot.

I omitted the alias SUDO='sudo $(history -p !!)' thing because I introduced a shorter, more useful shortcut that maps ^V to "recall last command go to BOL, upcase first word". This is actually better than an alis because

  • it's shorter
  • It allows you to back off before hitting CR. With 'sudo !!' it's easy to shoot your own foot especially if you (like me) are merging different histories from different terminal windows. (This can be achieved with: PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND". It's far from flawless, though)



You can’t perform that action at this time.