Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

echo "xxx" >> file_a is similar to what I want.

But it always attach string with a new line.

If I just want to attach string without a new line,

How to do it?

Thank you~

share|improve this question

2 Answers 2

up vote 3 down vote accepted

Use the printf builtin bash function

printf "xxx" >> file

or the -n option to echo, that suppress the newline.

share|improve this answer
    
printf is not only a Bash builtin, there's /usr/bin/printf too. Unlike the -n option of echo printf is definede by POSIX so it's usually the better choice. –  Florian Diesch Sep 1 '11 at 10:32
    
@Florian Diesch: I know, but we are talking about Ubuntu, where the default shell is bash, and where echo has the -n option, so it is not so important as it could be on a generic unix/linux site. Moreover, also sh's echo has -n option, so it is better to suggest alternatives that to be so radical, in my opinion. –  enzotib Sep 1 '11 at 10:38

Use printf:

printf "xxx" >> file_a 
share|improve this answer

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.