I have come across a weird behaviour in bash and would love to get to the bottom of it. If I execute
echo -e "\na\nb\nc\n"
at the command line, I get:
a
b
c
However, if I wrap it in an assignment such as:
A="$( echo -e "\na\nb\nc\n" )"
then I get
a
b
c
It doesn't show very well, but it has no trailing new line. It is as if the assignment is loosing the trailing new line (everything after the 'c'). Does anyone know how to turn this off?
That is, as echo always prints a 'newline' char at the end of a line automaticly, also with -e , eventhough, that is needed to supply more 'format commands'. printf on the other hand, handles 'format commands' with ease, but it just prints everything 'on one line', thus, you need to append the tailing \n , where as with echo -e you had gotten an extra newline.