linux - 无法在我的命令中重定向错误消息

标签 linux bash shell

我是 bash 脚本编写的新手,这基本上是我的 bash 脚本:

Z=`diff -Z $ref_out $exec_out | grep "[<>]" | wc -l` 2>/dev/null
if [ $Z -gt 0 ]; then
echo "*** testcase: [ stdout - FAILED ]"
else
echo "*** testcase: [ stdout - PASSED ]"
fi

我想抑制来自 diff 的错误消息,例如:

diff: No such file or directory

这可能是由于没有 $ref_out 或 $exec_out 文件造成的,尽管我重定向到/dev/null,但此错误消息仍然显示。 有什么帮助吗?

最佳答案

您需要 diff 的 stderr 才能转到/dev/null,因此它应该是:

Z=`diff -Z $ref_out $exec_out 2> /dev/null | grep "[<>]" | wc -l`

关于linux - 无法在我的命令中重定向错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50071602/

相关文章:

linux - 在目录中的文件内查找字符串然后复制它们

bash - 在 SLURM 之外使用 srun

linux - 没有覆盖 -n 被 cp 命令忽略

ruby-on-rails - tmux:我的其他终端还在运行吗?

bash - 需要帮助在 bash 脚本中使用 grep/egrep 匹配模式

linux - xterm 不运行 shell 脚本

linux - 如何获得一系列文件中具有最大差异的两个文件

Cygwin html 到浏览器

c - 在自定义 linux shell 中进行管道传输

bash - 递归 wget 不起作用