Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

You can print a command with:


But how do I append that command to a file? I thought:

!2500:p >> .bashrc

But that just prints everything including the ">> .bashrc" to stdout.

share|improve this question
up vote 4 down vote accepted

! repeats the numbered command, so you need to echo it. Use the :q modifier to quote the history substitution properly.

echo !2500:q >> .bashrc
share|improve this answer
Thanks, that works, but how do I preserve quotes and special characters. E.g. ls -al | grep "[[:space:]]\." – gregh Apr 18 '13 at 20:26
That's a bit more tricky – parkydr Apr 18 '13 at 21:02
You need to add the :q modifier to quote it properly: echo !2500:q >> .bashrc – Bradd Szonye Apr 18 '13 at 22:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .