Echo to file using SH without adding newline character

Hello!

I am able to do this in bash, using:

echo -ne HELLO > file.txt

and then, 'HELLO' is written into file.txt without the newline character to be added in the end of the file.

How is this possible to be done using sh instead of bash?
If I try something similar is SH, then inside file.txt, I will find:

-ne HELLO

which is quite funny :stuck_out_tongue:

Any help appreciated!:cool:

The 'printf' builtin is standard, and the same everywhere. It never prints newlines unless you give it \n's.

printf "hello" >> filename

Yes, this is what I want :slight_smile:
Thanks a lot for this!!!!

Just for completeness.
The syntax for echo has two main variants. The BSD style uses echo -n "HELLO" and the rest use echo "HELLO\c" .

The excellent Mascheck site has a comprehensive comparison of the variants of [/icode]echo[/icode] and printf .
echo and printf behaviour