Scenario:
You are doing your daily Bash shell stuff. You want to run a previous command so you type:
history | grep foocommand
Then you get a list of all the foocommand stuff you did for however long your history has kept track, in a list like so:
585 foocommand --baz --bleet 750 foocommand | grep quux 987 history grep | foocommand
You decide you want to run command 585, so you type
!585
Question: Just for curiosity, is there a way to take that final step out of the equation and still get the expected outcome? It would be nice if there were a way to say:
'grep through history and automatically run the first item on the list'
or
'grep through history and let me choose which item to run using the arrow keys'
The syntax
will run the last command that began with
foo.Failing that, bash uses the readline library for input, which supports the
history-search-forwardandhistory-search-backwardcommands that can be bound to keys of your choice. I’ve edited my./inputrcfile to bind them to F8 and Shift-F8, so that they work like Windows’ equivalent feature in the console when I connect with PuTTY: