Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

You can print a command with:

!2500:p

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

1 Answer 1

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
1  
You need to add the :q modifier to quote it properly: echo !2500:q >> .bashrc –  Bradd Szonye Apr 18 '13 at 22:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.