【发布时间】:2015-02-08 03:21:39
【问题描述】:
我需要检查收件人用户名是否在包含我班级所有用户的文件 /etc/passwd 中,但我尝试了几种不同的 if组合> 声明和 grep 没有成功。我能想到的最好的方法如下,但我认为它不能正常工作。
我的逻辑是,如果 grep 为 null,则用户无效。
send_email()
{
message=
address=
attachment=
validuser=1
until [ "$validuser" = "0" ]
do
echo "Enter the email address: "
read address
if [ -z grep $address /etc/passwd ]
then
validuser=0
else
validuser=1
fi
echo -n "Enter the subject of the message: "
read message
echo ""
echo "Enter the file you want to attach: "
read attachment
mail -s "$message" "$address"<"$attachment"
done
press_enter
}
【问题讨论】:
标签: bash if-statement null grep