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.

I would like to append text to a file. So I wrote in bash

echo text >> file.conf

However it doesn't leave a new line. So I can only do this once. How do I add a new line?

share|improve this question
2  
What do you mean? An extra newline? echo adds a newline by default. –  Dennis Williamson Jun 21 '10 at 9:58
1  
echo by default does leave a newline - do you need it to leave two? Also, if you're running this on a linux system and opening the file on a windows or mac system, make sure your editor supports *nix newlines, or it'll appear all on one line even though it's on multiple lines. –  Darth Android Jun 21 '10 at 10:01
add comment

2 Answers

up vote 21 down vote accepted

option 1:

% echo -e "text\n" >> file.conf

option 2:

% ( echo text ; echo "" ) >> file.conf

option 3:

% echo text >> file.conf
% echo ""  >> file.conf
share|improve this answer
2  
You can drop the empty argument (echo "" => echo). Also, option 4: echo $'text\n', which is useful for any command as the $'' is interpreted by bash. –  Roger Pate Jun 24 '10 at 23:55
add comment

Just to add to akira's response

Option 4:

use ctrl-v ctrl-m key combos twice to insert two newline control character in the terminal. Ctrl-v lets you insert control characters into the terminal. You could use the enter or return key instead of the ctrol-m if you like. It inserts the same thing.

This ends up looking like echo text^M^M >> file.conf

share|improve this answer
1  
If you need linefeeds instead of carriage returns (linux/unix), try echo "text^J^J" >> file.conf Typing ^J might actually insert a literal newline, just make sure to put the quotes and it'll be good. –  Darth Android Jun 21 '10 at 10:13
add comment

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.