Linux 查找匹配的`)和#x27;

Linux 查找匹配的`)和#x27;,linux,shell,Linux,Shell,当我尝试手动运行下面的脚本时,我得到以下两个错误输出。我不明白的是,为什么它会抱怨它找不到与“)”匹配的字符?如果我提取中的内容,然后/fi并将其放入一个文件中,然后自己运行它,它的工作方式就像它发送电子邮件一样正常 ./rsnapshot-log-checker: line 15: unexpected EOF while looking for matching `)' ./rsnapshot-log-checker: line 25: syntax error: unexpected en

当我尝试手动运行下面的脚本时,我得到以下两个错误输出。我不明白的是,为什么它会抱怨它找不到与
“)”
匹配的字符?如果我提取
中的内容,然后/fi
并将其放入一个文件中,然后自己运行它,它的工作方式就像它发送电子邮件一样正常

./rsnapshot-log-checker: line 15: unexpected EOF while looking for matching `)'
./rsnapshot-log-checker: line 25: syntax error: unexpected end of file

grep "ERROR" /var/log/rsnapshot.log | \
while read line ; do
        echo "$line" | grep "ERROR"
        if [ $? = 0 ]
        then
                to=warning@bla.com
                subject="Error rsnapshot - `hostname`"
                from=`hostname`@bla.com
                daemail=$(cat <<! <-- line 15
                        From: $from
                        To: $to Subject:
                        $subject You might want to check this... !) <-- maching haracter for )

                echo "$daemail" | /usr/sbin/sendmail -t
        fi
done
<-- line 25
/rsnapshot日志检查器:第15行:在查找匹配的`)时出现意外的EOF
./rsnapshot日志检查器:第25行:语法错误:文件意外结束
grep“ERROR”/var/log/rsnapshot.log|\
读行时;做
echo“$line”| grep“错误”
如果[$?=0]
然后
到=warning@bla.com
subject=“Error rsnapshot-`hostname`”
from=`hostname`@bla.com

daemail=$(cat此处文档定界符。

此处文档定界符。

您正在使用此处文档重定向操作符(您正在使用此处文档重定向操作符(是的,我可以看到此处的问题-但是Nishu answer提供了一个很好的干净解决方案,所以我接受了他的答案:)你+1是的,我可以看到这里的问题-但是Nishu的答案提供了一个很好的干净的解决方案,所以我接受了他的答案:)You+1是的,它似乎完成了这个技巧。虽然它仍然让我有点困惑,为什么它自己工作,而不是在if语句中。是的,它似乎完成了这个技巧。虽然它仍然让我有点困惑,为什么它自己工作,而不是在if语句中工作。
daemail=$(cat
         echo "From:" $from
         echo  "To:" $to "Subject:"
         echo  $subject "You might want to check this... !")