Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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

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
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

Small variation on the theme, although somewhat verbose

awk '1;END{printf "xxx"}' input_file > tmp_file && mv tmp_file input_file 
share|improve this answer

Your Answer


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.