【发布时间】:2014-03-18 15:18:34
【问题描述】:
我正在创建一个 shell 脚本,它使用邮件功能接收用户输入和文本的人。我希望让它更先进。现在它一次只能给一个人发短信,我希望它能够通过用户输入“全部”来给多人甚至每个人发短信。
#!/bin/sh
# Prefix the numbers with something
number_Joe=8881235555
number_Bob=8881235556
echo "Who do you want to text?:(i.e. Joe, Bob, etc)"
read name
echo "What do you want to say?:"
read quote
# Remove any dangerous characters that the user enters
sanitized=$(printf "%s" "$name" | tr -cd 'a-zA-Z')
#Look up by evaluating e.g. "number=$number_Joe"
eval "number=\$number_$sanitized"
if [ "$number" ]
then
echo "texting $name ($number) with $quote"
printf "%s\n" "$quote" | mailx -s "Text Message via email" "$number@txt.att.net"
else
echo "Unknown user"
exit 1
fi
另外,有没有更简洁的方法来引入一个包含数字而不是脚本的外部 txt 文件? (注意:我们仍然有 bash
【问题讨论】: