You are getting the same data in different formats because it is quoted in one instance, and not in the other. Put double quotes around the mail command, and the newlines will be preserved:
echo "$result" | mailx -s "KLON ILK BILDIRIM SONUCLARI" $MAIL_LIST
The reason this happens is that the shell expands $result
before the echo
is performed. Since the default IFS includes newlines, the newlines inside $result
are treated as field separators instead of actual newlines. When you quote the variable, you treat everything inside the variable as a single argument, and hence the newlines are retained.