我正在尝试创建一个命令,该命令将允许我检查网站上的特定单词。我在行的末尾使用\将其换行到下一个字符(不确定在这里是否正确使用了这些字符),这些字符不在我的脚本中。
check=$(lynx -source $1 | grep -i $2)
if [[ $check == *"$2"* ]]
then
/usr/local/bin/sendemail -o tls=yes -f ***@gmail.com -t\
[email protected] -s smtp.gmail.com:587 -xu ***@gmail.com -xp *** -u\
$1 -m "contains the word " $2 ".";
else
/usr/local/bin/sendemail -o tls=yes -f ***@gmail.com -t\
[email protected] -s smtp.gmail.com:587 -xu ***@gmail.com -xp *** -u\
$1 -m "does not contain the word " $2 ".";
fi
您通常grep
不区分大小写地检查输出,然后使用区分大小写的glob模式检查grep的输出。
改为执行以下操作:
if lynx -source "$1" | grep -qi "$2"; then
msg="contains the word '$2'."
else
msg="does not contain the word '$2'."
fi
/usr/local/bin/sendemail -o tls=yes -f ***@gmail.com -t [email protected] -s smtp.gmail.com:587 -xu ***@gmail.com -xp *** -u "$1" -m "$msg"
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句