문제

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

mailx -s "subject" foo@bar.com

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" foo@bar.com \n Body Text \n . 

in one go.

Thank you!

도움이 되었습니까?

해결책

mailx -s "subject" foo@bar.com <<<$'\n Body Text \n'

다른 팁

Thank you to both Alfe and Joachim PileBorg, I now have two solutions! The one Alfe provided works, as does:

echo "body" | mailx -s "subject" foo@bar.com 

which, though my Unix is rusty, I imagine does basically the same thing.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top