How do I write non-ASCII characters using echo?

On my terminal,

printf '\012' >>output.txt

works for both the octal representation of the ascii character, and the corresponding hexadecimal:

printf '\xA' >>output.txt

The command

echo -en '\012' >>output.txt

however, does not function properly. Only hexadecimals seem to work with echo -e. The -n removes the default extra newline from echo.


If you care about portability, you'll drop echo and use printf(1):

printf '\012'

Use

echo -e "\012"