I know about the bash feature !text, which runs the last command starting with "text". But it seems not to work, when "text" contains space. Sometimes it is useful to search for something, containing spaces.
history | grep ping 514 ping 192.168.100.2 515 ping 192.168.100.3 516 ping 192.168.100.4 517 ping google.com 518 ping 192.168.100.5 519 ping 192.168.100.6 520 ping 192.168.100.7
I want to call the line "ping google.com", using the ! feature. I tried some things, but they failed:
this is the standard behavior, it runs the last ping command
/root# !ping ping 192.168.100.7
A simple string with space after ! does not work
/root# !ping google ping 192.168.100.7 google
As I know, quotes tell bash to interpret a string with space as a single string, instead of 2 separate strings. But here it does not work as expected.
/root# !"ping google" bash: !"ping: event not found /root# !'ping google' bash: !'ping: event not found /root# "!ping google" "ping 192.168.100.7 google google" /root# '!ping google' bash: !ping google: command not found /root# !\"ping google\" bash: !\"ping: event not found /root# !(ping google) bash: !: event not found
This calls the command, but it will call the last command, containing the string. I want only commands, beginning with "ping"
/root# !?google ping google.com
Is it possible to do what I want?