我是 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/