DEV Community

Discussion on: Bash Shell Tricks

Collapse
 
geoff profile image
Geoff Davis • Edited

Great write-up!

Quick note, if you are using the command edit/replace feature and are using a conditional command construct (echo "first command" && echo "second command!") the ^foo^bar syntax only replaces the first instance of the searched text.

To replace every instance of that searched text, you have to use !!:gs/foo/bar; going back to my first example:

To replace all the instances of command in...

echo "first command" && echo "second command!"

...you have to execute...

!!:gs/command/echo

...to output:

first echo
second echo!
Enter fullscreen mode Exit fullscreen mode

Further reading: Stack exchange

Collapse
 
bhaskar_vk profile image
Bhaskar Karambelkar

Yup I found out about it sometime after I wrote the original post almost 10 years ago. Thanks for the reminder!