To print values in diferent line in mail body shell script

1

Below is the code to print contents of files present in the directory File contents are :

apple 
banana 
grapes 
mango

names=()

FILES=/path_to_dir/*
for f in $FILES
do
   names+=($f)
done
result="$(cat ${names[@]})"
echo "$result"

echo "The  names are "$result"" | mailx -s "names are " abc@gmail.com

for this I am getting below output for result variable

apple 
banana 
grapes 
mango

However when I print "$result" in email I got below output in email's text:

apple banana grapes mango

I want to send names in email with multiline like this :

apple 
banana 
grapes 
mango

How to achieve the same?

user

Posted 2015-12-12T05:56:56.233

Reputation: 199

Answers

0

Try with echo -e "The names are:\n" "$result"

The -e option allows the newline sign \n interpretation; variable is then expanded correctly, by having its own double quotes.

SΛLVΘ

Posted 2015-12-12T05:56:56.233

Reputation: 1 157