"echo -e" does not display trailing \n?

52 views Asked by At

I'm trying to debug why echo -e behaves so weirdly on MacOS/Linux that it does not print the trailing '\n'. Is it how echo command works?

SCRIPT

#!/bin/bash -e

myVar='AA\nBB\n\n\n\n\n\n\n\n\n'

echo ">${myVar}<"

myVar="$(echo -e "${myVar}")"

echo ">${myVar}<"

RESULT :

>AA\nBB\n\n\n\n\n\n\n\n\n<
>AA
BB<
0

There are 0 answers