Sunday, June 21, 2009

How to reuse a command in Bash command prompt

Suppose you have executed the following series of scripts(commands) for an argument say 12.34.

$ ./ 12.34 && ./ 12.34 && rm /tmp/12.34.lck

Now if you need to repeat the same command, but this time for argument 11.3, then you can always go to command history (basically last command using your arrow keys), edit the 12.34 to 11.3 and you are done.

But, sometime if you don't want to take the risk of making any typo, you can change the argument in all the places using this:

$ !!:gs/12.34/11.3/

Which is basically:

./ 11.3 && ./ 11.3 && rm /tmp/11.3.lck

Related posts:
- Accessing last argument of previous command
- Recall last argument of last command in bash

No comments:

© Jadu Saikia