Thursday, August 27, 2009

Bash - save command without executing it


In Bash, if you have typed a very long command (applicable to shorter commands too :-)), and then realize you don't want to execute it yet, don't delete it.

Then what ?

Ans :

Simply append a # to the beginning of the line (command), and then hit enter.

So bash is not going to execute this command (as its commented), but will store it in history. So later you can go back, remove the # from the front, and execute it.

e.g.





Lets see my history (output of history command)





Well, if you are wondering how I have added the "command execution timestamp" to the history command output, here is the tip

And if you want to know how I made my Primary bash prompt (PS1) a colorful one, here is another tip

3 comments:

Unknown said...

I added this to my .inputrc.

"\C-o": insert-comment

so I can hit crtl-o so the # is added automatically. Also I don't have to hit enter.

rattus said...

Please don't forget that there is a shortcut for this: ESC # (it's doing ^A#^M).

Unknown said...

@Rattus, thats a real great tip. I never knew that. Thanks.

© Jadu Saikia www.UNIXCL.com