gpt4 book ai didi

linux - 比较输入和输出 - bash

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:40:32 24 4
gpt4 key购买 nike

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

我到底怎么比较

我在想,

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

有什么建议吗?

最佳答案

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

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

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

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

diff如果你想知道有什么区别。

关于linux - 比较输入和输出 - bash,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12666662/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com