【发布时间】:2015-07-16 21:40:35
【问题描述】:
我的系统 (rhel5) 不支持 mailx 的 -E 选项(如果正文为空则不发送电子邮件)。是否有一个我可以用来模拟这个功能的衬垫?例如,第一个会发送,但第二个不会
echo 'hello there' | blah | mailx -s 'test email' me@you.com
echo '' | blah | mailx -s 'test email' me@you.com
【问题讨论】:
我的系统 (rhel5) 不支持 mailx 的 -E 选项(如果正文为空则不发送电子邮件)。是否有一个我可以用来模拟这个功能的衬垫?例如,第一个会发送,但第二个不会
echo 'hello there' | blah | mailx -s 'test email' me@you.com
echo '' | blah | mailx -s 'test email' me@you.com
【问题讨论】:
嗯。 “单线”是相对而言的,因为这些在技术上是单线,但它们可能不适合您:
stuff=$(echo 'hello there') ; [ -n "${stuff}" ] && echo ${stuff} | mailx -s 'test email' me@you.com
stuff=$(echo '') ; [ -n "${stuff}" ] && echo ${stuff} | mailx -s 'test email' me@you.com
【讨论】:
你可以用一个技巧而不是一个程序来尝试它:
msg='hello there' && [ -n "$msg" ] && echo "$msg" | mailx -s 'test email' me@you.com
如果您的消息来自另一个脚本,您必须将其运行为
msg="$(get_it)" && [ -n "$msg" ] && echo "$msg" | mailx -s 'test email' me@you.com
如果不支持[ ... ],您也可以使用[[ ... ]]:
msg="$(get_it)" && [[ -n "$msg" ]] && echo "$msg" | mailx -s 'test email' me@you.com
【讨论】: