mailx UNIX command in one line

nightTrevors picture nightTrevors · Nov 6, 2013 · Viewed 8.5k times · Source

What's the best way to send mail from the shell with one line of code?

mailx -s "subject" [email protected]

Enters into line by line entry of the body and the message is only sent with termination of Ctrl+D or '.'

Since I am accessing the system command through another program, I'd like to be able to do something like:

mailx -s "subject" [email protected] \n Body Text \n . 

in one go.

Thank you!

Answer

Alfe picture Alfe · Nov 6, 2013
mailx -s "subject" [email protected] <<<$'\n Body Text \n'