If you look at the manual pages for bash or history (3readline) under "Extending History"> "Event Labeling", you will see commands to execute this type.
!?prof?
will display the most recent command containing "prof" and execute it immediately. If you want to print the command without executing it, you can add ": p"
!?prof?:p
To edit a command on the command line using the example above, enter:
!?prof
(do not press enter) and press M - ^
They use the bash extension tool. They receive only the most recent match.
If you want to write scripts or aliases, look at the bash man page in the built-in fc and history commands (-p or -s). Also "shopt -s histreedit".
Here is an example of an alias:
alias dothis='`history -p "!?jpg?"`'
(those that are quoted only inside single quotes).
With some of these commands you can do cool "s / old / new" and other things.
Dennis Williamson Apr 11 '09 at 3:34 2009-04-11 03:34
source share