Reputation: 2025
I am writing a shell script, it takes some value with sql plus and put it into variable called "result".
when i wrote echo "$result" the output is (as expected) :
1 2029
-32 9
-19 2579
-36 1039
-35 2
-33 1336
but when i emailed to my mail address, the mail is in format:
1 2029 -32 9 -19 2579 -36 1039 -35 2 -33 1336
here is my code:
result=$(sqlplus -s user/password%@IDB << EOF
set trimspool on;
set linesize 32000;
SET SPACE 0;
set HEADING off;
set feedback off;
SELECT ...
exit;
EOF)
echo -e $result | mailx -s "KLON ILK BILDIRIM SONUCLARI" $MAIL_LIST
how can i put it into right format and why the result of "echo result" and mail format is different?
Upvotes: 0
Views: 163
Reputation: 2169
Use brackets. You don't need to keep results in variable for this action.
{
sqlplus -s user/password%@IDB << EOF
something
...
exit;
EOF
} | mailx -s "KLON ILK BILDIRIM SONUCLARI" $MAIL_LIST
Upvotes: 1
Reputation: 11796
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.
Upvotes: 2