How to fix echo printing literal \n (backslash newline)
Problem:
You want to echo into a file like this:
echo_example.sh
echo "\ntest\n" > test.txtbut after doing that, test.txt contains the literal
echo_literal_output.txt
\ntest\nSolution
Use echo -e (-e means: interpret backslash escapes):
echo_fix.sh
echo -e "\ntest\n" > test.txtAfter doing that, test.txt will contain test with a newline before and after.
Check out similar posts by category:
Linux
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow