How can I alias to `!!` (last command)?

5,531
alias dl='fc -s'

See http://www.gnu.org/software/bash/manual/bashref.html#Bash-History-Builtins

Share:
5,531

Related videos on Youtube

Владислав Щербин
Author by

Владислав Щербин

Updated on September 18, 2022

Comments

  • Владислав Щербин
    Владислав Щербин almost 2 years

    !! in bash runs last command. I find it too difficult to type given how much I use it. alias to the rescue, I presumed.

    Or not. I tried:

    $ alias dl='!!'               # Aliasing
    $ echo Testing123             # Here's something to test on
    Testing123
    $ dl                          # Testing alias
    bash: !!: command not found
    $                             # I AM DISAPPOINT
    

    Without quotes also fails.

    What's up?

  • Владислав Щербин
    Владислав Щербин over 12 years
    Works! Still curious though: What makes !! un-aliasable?
  • Angel Todorov
    Angel Todorov over 12 years
    I can't find anything quickly in the manual but I'm guessing that bash performs any history expansions before substituting aliases. So the shell only sees the command "!!" which clearly doesn't exist.