Reputation: 1
So I have this script to check if a number is the one I expected to be. But I want to test it with the C program output directly, not storing the results on a file.
#!/bin/bash
j=0;
for i in {1..100};
do ./a.out > output;
cmp expected output || let "j+=1";
done
echo $j;
The ./a.out is referred to a program that prints a number. I want to check if it's the same as the stored on expected but without using files
Upvotes: 0
Views: 55
Reputation: 6345
This worked fine for me (by replacing a.out with a simple echo script):
#!/bin/bash
j=0;
for i in {1..100};
cmp expected <(./a.out) || let "j+=1";
done
echo $j;
man 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.
Upvotes: 1
Reputation: 781513
You can substitute the output of a command into the command line with $(command)
.
expected=$(< expected)
j=0
for i in {1..100}; do
test "$(./a.out)" = "$expected" || let j+=1
done
echo $j
Upvotes: 0