【发布时间】:2016-06-25 13:04:00
【问题描述】:
在这里,我想使用 unix shell 脚本发送邮件。
我使用以下脚本进行简单的邮寄:
echo 'Message body goes here' | mail -s 'subject line goes here' email@provider.com
注意:现在我想使用如下所示的变量发送主题来自其他文件的邮件。
文件 1:
该文件包含以下脚本:
#!/bin/bash
subjectvariable="Subject is here"
export $subjectvariable
我想得到这个$subjectvariable 应该在邮件命令中用作变量。
我的尝试:
文件 2:
#!/bin/bash
echo 'Message body goes here' | mail -s "$subjectvariable" email@provider.com
但在输出中我没有得到主题。
只是 echo 命令的变量工作文件,如下图所示:
【问题讨论】:
-
我认为在第一个脚本中应该是
export subjectvariable="Subject is here。注意:该变量仅可用于子进程。所以文件 2 必须从文件 1 运行。 -
您需要使用
source ./setSubject.sh获取主题脚本才能在当前 shell 中设置变量 -
@anubhava,我已经导出了那个变量。那么还需要将源文件放到当前的shell中吗?
-
Export 不能使其对父 shell 可用
-
@anubhava,好的。让我给你看点东西。只需查看我更新的帖子,请回复。
标签: bash shell email command-line command