读取shell脚本中sed命令的错误输出

读取shell脚本中sed命令的错误输出,sed,Sed,如果下面的sed命令失败,我想知道失败的原因,即错误输出也应作为电子邮件的一部分添加。如何做到这一点 代码是: sed -e abc.txt > /net/abc.com/test/abc.txt #Sending email if [ -f /net/abc.com/test/abc.txt ]; then echo "content of abc.txt saved to server" | mail -s "Content of abc" dave@klm.com

如果下面的sed命令失败,我想知道失败的原因,即错误输出也应作为电子邮件的一部分添加。如何做到这一点

代码是:

sed -e  abc.txt > /net/abc.com/test/abc.txt

#Sending email

if [ -f /net/abc.com/test/abc.txt ]; then
       echo "content of abc.txt saved to server" | mail -s "Content of abc" dave@klm.com
else
       echo "File does not exist"
fi

在“文件不存在”之后,应附加sed失败的原因。

sed命令将其错误发送到(令人惊讶的)标准错误。所以你可以抓住它,并根据以下记录对其进行特殊处理:

pax> echo hello | sed 's/missing/terminator' >outfile 2>errfile

pax> cat outfile

pax> cat errfile
sed: -e expression #1, char 20: unterminated `s' command

sed
命令将其错误发送到(令人惊讶的是)标准错误。所以你可以抓住它,并根据以下记录对其进行特殊处理:

pax> echo hello | sed 's/missing/terminator' >outfile 2>errfile

pax> cat outfile

pax> cat errfile
sed: -e expression #1, char 20: unterminated `s' command

sed
命令将其错误发送到(令人惊讶的是)标准错误。所以你可以抓住它,并根据以下记录对其进行特殊处理:

pax> echo hello | sed 's/missing/terminator' >outfile 2>errfile

pax> cat outfile

pax> cat errfile
sed: -e expression #1, char 20: unterminated `s' command

sed
命令将其错误发送到(令人惊讶的是)标准错误。所以你可以抓住它,并根据以下记录对其进行特殊处理:

pax> echo hello | sed 's/missing/terminator' >outfile 2>errfile

pax> cat outfile

pax> cat errfile
sed: -e expression #1, char 20: unterminated `s' command

sed命令将始终失败,因为错过了操作sed命令将始终失败,因为错过了操作sed命令将始终失败,因为错过了操作sed命令将始终失败,因为错过了操作sed命令将始终失败