issue with Email Body

Hi,

I have written shell program to send email as below -

#!/bin/ksh
filename=`ls -ltrh *.Z`
echo $filename |mailx -s "FOR TESTING" rahul.b@infotech.net 

I am getting the email but email body is -

-rw-rw-r-- 1 bahulra dba 173M Mar 22 04:37 corphist.txt.Z -rw-rw-r-- 1 bahulra dba 107M Mar 22 04:37 corphist2.txt.Z -rw-rw-r-- 1 bahulra dba 305 Mar 22 04:59 corpdates.txt.Z -rw-rw-r-- 1 bahulra dba 77M Mar 22 04:59 corpmstr.txt.Z

Instead I want email body as -

-rw-rw-r-- 1 bahulra dba 173M Mar 22 04:37 corphist.txt.Z
-rw-rw-r-- 1 bahulra dba 107M Mar 22 04:37 corphist2.txt.Z
-rw-rw-r-- 1 bahulra dba 305 Mar 22 04:59 corpdates.txt.Z
-rw-rw-r-- 1 bahulra dba 77M Mar 22 04:59 corpmstr.txt.Z

Thankx,
Rahul

I've used bash. Check if this for you.

#!/bin/bash
OLDIFS=$IFS
IFS=\n
filename=`ls -ltrh *.Z`
echo $filename | mailx -s "FOR TESTING" rahul.b@infotech.net
IFS=$OLDIFS

Also, try doing this: ls -ltrh *.Z | mailx...... instead of storing in a var and then echo-ing it.

1 Like

Thankx for the solution.

your code is working fine. Also i tried with

ls -ltrh *.Z | mailx......

and able to produce desired result.

Thankx!!
Rahul.

Quote the variable to preserve the new line character..