0

I'm using bash shell. If I want to execute the last echo command, I can run

history | grep echo

and then grab the last echo command from what is displayed and run it. I was wondering, is there a shorter way to do this? I'm happy to use another shell if that allows me to somehow more easily execute the last "echo" command if all I know is the command started with "echo."

2 Answers 2

5

type to command line this: !echo

5

Using reverse interactive search:

  • hit Ctrlr
  • start typing for the command you want
  • when the shell has found the one you want, hit Enter.

If you want to use a previous echo command

  • hit Ctrlr
  • type echo
  • hit Ctrlr again, repeatedly until you find the command you want.
  • if you go too far back in history, Ctrls searches in the opposite direction.

If you don't want to execute the command, but edit it a bit, when you find the command you want:

  • don't hit Enter
  • instead, hit the ESC or left or right arrow key

If you want to reject the command,

  • clear the command-line Ctrlg or Ctrlc (the latter leaves the line behind, though).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .