【发布时间】:2022-01-11 22:00:17
【问题描述】:
我正在尝试将命令的输出重定向到 mailx。
if grep -B 1 line $curccrtpick; then
grep -B 1 line $curccrtpick | head -2 > tempmsg
mail -s "String found in $curccrtpick" -r test@test.com dummy@test.com < tempmsg
#rm tempmsg
else
echo nothing
fi
但它以附件形式出现的二进制文件(ATT00001.bin)
当我跑步时
tr -d '[\015\200-\377]' < tempmsg > tempmsg1
并将该文件重定向到 mailx 我在一个衬里收到电子邮件:
thefirstlinethesecondline
什么时候应该有两个
thefirstline
thesecondline
【问题讨论】:
-
你能
read -r -d '' content < tempmsg; printf '%q\n' "$content"并将输出添加到问题中吗? -
@fravadona 输出已添加。谢谢
-
在 UNIX 术语中,不以
\n字符结尾的文件被视为二进制文件。 "$curccrtpick" 的最后一个\n已在代码中的某处被删除 -
@fravadona 我已经更新了最新结果。
-
您可以使用
echo >> tempmsg1快速解决问题,但您应该搜索最后一个换行符消失的位置(可能在$( )中)