Separating output after final character

I'm trying to write a script that will email the contents of my Application folder to me.

cd /Applications
ListApps=$(ls)
echo $ListApps | mail -s "Application Check" myself@myemail.com

This sends it in a paragraphed block i.e:

Adobe Acrobat Reader.app App Store.app Atom.app
Calculator.app Calendar.app

Is it possible to look for the final character for each string and put it onto a new line? i.e.

Adobe Acrobat Reader.app
App Store.app
Atom.app

I'd like to avoid specifically targeting the .app because I have a couple of directories in my Applications directory.

You can tell the ls command to display one file per line.

cd /Applications
ListApps=$(ls -1)
echo "$ListApps" | mail -s "Application Check" myself@myemail.com
1 Like

That's worked, thankyou so much!

Hello $shell_Learner,

cero's solution is correct you could use " to have the special meaning of new line saved while echoing that variable, you could directly try following and without saving the values of ls command as follows too.

ls /Applications | mail -s "Application Check" your_email_id
OR
ls -l /Applications | mail -s "Application Check" your_email_id

Thanks,
R. Singh

If you would prefer the contents emailed as an attachment rather than within the body of the message :-

ls -l > dirlist
echo "Please find the attached directory listing" | mailx -s "direcory" -a dirlist firstname.surname@domain.co.uk