EDIT: found mistake, it was actually bug in my program, I had > instead of >= in my for loop that reads coefficients.
I'm fairly new to linux, and I need help with bash scripting.
I have C program, that takes data from stdin in this form:
Degree of A:
nA
Coefficients of A:
.... //reads nA+1 numbers, separated by white space (e.g. 1 2 3 8 -5 ...)
Degree of B:
nB
Coefficients of B:
.... //reads nB+1 numbers, same as A.
I'm trying to debug my program, since it has trouble with big amounts of numbers (takes a lot of time, when it shouldn't). So I created bash script that generates lot of numbers, then stores them in file, edits it a little bit and then sends it to stdin of my program, here is the script:
#!/bin/bash
rm tmp.txt
COUNT=0
for i in range {0..5000}
do
COUNT=`expr $COUNT + 1`
echo $(($RANDOM%100 - 50)) >> tmp.txt
done
echo 1 > in1.txt
echo '1 2' >> in1.txt
echo $(($COUNT-1)) >> in1.txt
cat tmp.txt |tr '\n' ' ' >> in1.txt
time ./a.out < in1.txt
This creates file called tmp.txt, that has lots of numbers, each on a new line. So I then echo few numbers to a new file called in1.txt (they correspond to A from example above). After that, I echo number of B's into that file and then take tmp.txt, replace \n with white space and append it to that file. After all that is done, I time how long does the program execute.
Problem is, it has trouble with the last line. Program executes, but with the wrong data. Here is snippet of in1.txt file:
1
1 2
5001
-30 50 <long line of numbers ...>
What am I doing wrong here?