gpt4 book ai didi

c - 我怎样才能改变这个脚本

转载 作者:行者123 更新时间:2023-11-30 15:00:23 25 4
gpt4 key购买 nike

所以我有这个脚本来检查一个数字是否是我期望的数字。但我想直接用C程序输出来测试它,而不是将结果存储在文件中。

#!/bin/bash
j=0;
for i in {1..100};
do ./a.out > output;
cmp expected output || let "j+=1";
done
echo $j;

./a.out 是指打印数字的程序。我想检查它是否与预期存储的相同但不使用文件

最佳答案

这对我来说效果很好(通过用简单的 echo 脚本替换 a.out):

#!/bin/bash
j=0;
for i in {1..100};
cmp expected <(./a.out) || let "j+=1";
done
echo $j;

男人 bash :

Process Substitution
Process substitution allows a process's input or output to be referred to using a filename. It takes the form of <(list) or >(list). The process list is run asynchronously, and its input or output appears as a filename.

关于c - 我怎样才能改变这个脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42148332/

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