Bash history question

So, in my bash history I have:

$ gnome-extensions disable '' ; sleep 1 ; gnome-extensions enable ''

$ history | grep gnome-extensions
  470  gnome-extensions disable '' ; sleep 1 ; gnome-extensions enable ''
  471  history | grep gnome-extensions

Now, I when I invoke the command using the exclamation mark, it works with the line number, but if I type the first few letters for some reason it runs something slightly different:

$ !470
gnome-extensions disable '' ; sleep 1 ; gnome-extensions enable ''
# above is correct

# below is broken, notice the "enable" part somehow gets messed up:
$ !gnome-extensions
gnome-extensions disable '' ; sleep 1 ; gnome-extensions enableextensions
  gnome-extensions COMMAND [ARGS…]

What’s up with that?

P.S. I am using bash

Not a direct answer, but I use history with the help of these definitions in ~/.bashrc:

bind '"\e[A":history-search-backward'      # up arrow
bind '"\e[B":history-search-forward'       # down arrow

With them I can find older commands easily:

  • just using up and down arrow keys
  • by writing the start of a command and pressing up and down arrows I will get the command I want, even when there are many commands in history starting the same

This way I never have to use ! and a number (which for me seems quite clumsy).


Can confirm these are awesome. I’ve added them as well, so now I no longer need to suffer (typing “gnome-ext” and pressing up arrow looks up the correct command).

So thank you for this. While not an answer, it is indeed even better than an answer.

Still curious though to find out why bash is behaving like this with the exclamation mark…

Don’t really know, might be something to do with long lines, or simply a bug… but just guessing here.

Bash should be quite well tested as it is used a lot.

If you know the wanted command’s name

history | grep command-name


Nice tips, thanks…

I use CTRL-R.