Alias `su 0` to `su -`

April 22nd, 2013

You can only alias a command, not a command + argument(s). The process of automatically fixing oft’ mistyped arguments involves 2 steps:
1. Alias the command to a shell script
2. Write shell script to replace the erroneous argument with the real one.

For step one, create the following alias:
alias su="~/bin/ $@"

Although I found many sources claiming you can’t redirect all a commands arguments to another command, $@ does exactly that. I mention this in case my system happens to be the exception rather than the rule.

The script, ~/bin/

# Alias 'su 0' to 'su -'
# Created by KJ Coop on Sun Apr 21 23:24:28 PDT 2013
# Yoinked from
if [ "$1" == "0" ]; then
    # I can't `su - @#` because it expands into `su - 0...` so I'm just
    # assuming there's a max of 2 arguments: su [dash] [username]
    su - "$2"
    su $@
exit 0;

Comments are closed.