12

!! 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?

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
  • 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 08 '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 08 '12 at 19:51
  • @bdowning As cjm; my Shift-finger wants a break. – Anko - inactive in protest Mar 08 '12 at 19:53
  • Get a dvorak. qwerty stair-step keyboards are an anachronism left over from typewriters designed to slow you down and make you hands hurt. After 20 years of emacs, my fingers are like pretzels – bsd Mar 08 '12 at 20:42
  • @bdowning I've considered dvorak and colemak, but I move between multiple computers daily and qwerty is the unfortunate hardware standard. All those C-chords on Emacs are little reasons I prefer vim. :-) – Anko - inactive in protest Mar 08 '12 at 21:24
  • 1
    @bdowning: [according to *"Why QWERTY was invented"*, slowing you down was not a design objective of querty, but *reducing clashes*](http://home.earthlink.net/~dcrehr/whyqwert.html) (of course, keyboards don't clash at all, so other layouts might be more favourable) – sr_ Mar 09 '12 at 13:27
  • 2
    @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 09 '12 at 13:30

1 Answers1

19
alias dl='fc -s'

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

glenn jackman
  • 84,176
  • 15
  • 116
  • 168
  • 1
    Works! Still curious though: What makes `!!` un-aliasable? – Anko - inactive in protest Mar 08 '12 at 19:57
  • 7
    I can't find anything quickly in [the manual](http://www.gnu.org/software/bash/manual/bashref.html) 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 08 '12 at 20:17