Bash Tip: Modify and repeat last command…

I will often issue a command at the bash prompt and want to re-issue the same command, albeit with a slight modification. This can be a pain if the command is lengthy and I’ve often thought it should be easier. I finally got around to trying something new to make it easier.

1. search for a package with yum

sudo yum --enablerepo=epel search ssldump

2. issue the same command, although replace search with install:

$(echo !! | sed 's/search/install/')

Now that I typed that all out, I realize that it’s not much of a savings, and with a different command, it could be more painful although it seems clever.

After a bit of research, I came across this shorter version (second step only for brevity):

^search^install^

Much more elegant for single occurence replacement. For multiple occurences, try this previous one again, with an added /g:

$(echo !! | sed 's/search/install/g')

Check out the bash reference.


Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *