I'm running a script that SSHs into a server and then runs several commands. I then want to send these using the mail command. I run:result=$(ssh user@host 'kinit -k -t /path/to/dir/`whoami`.`hostname -s`.keytab `whoami`/`hostname -f`@host.file.thing && hdfs dfs -count -q -h -v /path/to/&& echo ******************************************** && hdfs dfs -du -h /path/to/dir&& echo ******************************************** && hdfs dfs -du -h /path/to/sub/dir')The resuls aren't that important but for some reason I can't figure out, this results in one rogue ^M being put in my ~200 line result. As a result when I try to email it, it appears as a binary file in Microsoft Outlook.What I'm trying to do is echo $result, sed it to remove the ^M and then mail it:echo $result | sed -e s/^M// | mail -s Results joe.bloggs@gmail.comI've also tried echo $result | sed -e s/'`echo \105`'// | mail -s Results joe.bloggs@gmail.comWhich does not work (that's from memory so syntax may be off).How can I have the results of the variable print in the body of the message? Ideally I'd like to avoid outputting to a file or attaching it as a file.
Replacing ^M with sed in a bash script
bash;sed;mailx