!! 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
$ dl                          # Testing alias
bash: !!: command not found
$                             # I AM DISAPPOINT

Without quotes also fails.

What's up?

  • 1
    Aliases usually shorten the length of frequently typed commands, or adding frequently used switches. What's the point of even needing an alias for !!? – bsd Mar 8 '12 at 19:44
  • 2
    @bdowning, presumably so you don't have to hit Shift and reach up in the corner of the keyboard. – cjm Mar 8 '12 at 19:51
  • @bdowning As cjm; my Shift-finger wants a break. – Anko Mar 8 '12 at 19:53
  • 1
    @bdowning: according to "Why QWERTY was invented", slowing you down was not a design objective of querty, but reducing clashes (of course, keyboards don't clash at all, so other layouts might be more favourable) – sr_ Mar 9 '12 at 13:27
  • 1
    @sr_ The clashes occurred because of the speed of typists. If you wish to continue this I suggest we move to a chat room. I don't care to continue, the less typing the better :) – bsd Mar 9 '12 at 13:30
alias dl='fc -s'

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

  • Works! Still curious though: What makes !! un-aliasable? – Anko Mar 8 '12 at 19:57
  • 7
    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. – glenn jackman Mar 8 '12 at 20:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.