problem in bash echo

I am using the echo command to send the output to the file.
I am using the following code:

echo "service started successfully\n" > log

But when I do:

cat log

I get:
service started successfully\n
Instead of a newline after the "successfully"

Why is that and how can I fix it?

echo -e "service started successfully\n" > log
1 Like

use printf

printf "test\n" > test.txt

thanks, it worked.