我正在做以下事情:
x="Hello to the world of tomorrow\n <pre>";
x="${x}$(tail -n 50 log/logfile.log)"
x="${x}</pre>";
echo -e $x | ./perlscript
Run Code Online (Sandbox Code Playgroud)
Perl 脚本:
#!perl
# perlscript
open(MAIL, "sendmail -t")
print MAIL "EMAIL HEADERS\n\n"
print MAIL <STDIN>
close(MAIL);
Run Code Online (Sandbox Code Playgroud)
当我收到电子邮件时,日志文件\n的<pre>标签内没有任何内容。在Hello to the world of tomorrow正常工作和\n表示。
我如何才能tail不删除任何\n,或者它是链条下游/上游的东西?
命令 echo 中缺少双引号:
echo -e "$x" | ./perlscript
Run Code Online (Sandbox Code Playgroud)
这是一种更简洁、更惯用的方式来完成您正在尝试做的事情:
{ printf 'Hello to the world of tomorrow\n <pre>\n'
tail -n 50 log/logfile.log
printf '</pre>\n'; } | ./perlscript
Run Code Online (Sandbox Code Playgroud)
无论如何,当您只是要按顺序将其推送到管道中时,没有理由首先将所有输出缓冲在变量中。