比较输入和输出 - bash

时间:2012-10-01 01:44:18

标签: linux bash

假设我有一个输入文件和一个输出文件(test.in和test.out)和一个程序“./myprogram”,标准输入重定向来自test.in并使用从标准输出中捕获的结果与test.out进行比较

我究竟能比较

我想,

 if [ $(myprogram < test.in) == $(cat test.out) ]

有什么建议吗?

2 个答案:

答案 0 :(得分:4)

使用cmp 并指定-作为要比较的文件之一,告诉它使用stdin。

if myprogram < test.in | cmp -s - test.out; then

如果要在不创建临时文件的情况下比较两个命令的输出,请使用<(cmd)功能。 (在man bash中搜索“过程替换”。)

if cmp -s <(myprogram < test1.in) <(myprogram < test2.in); then

diff如果您想知道其中的差异。

答案 1 :(得分:0)

我会使用差异。像这样:

if cat test.in | myprogram | diff - test.out

相关问题