Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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:
Coefficients of A:
.... //reads nA+1 numbers, separated by white space (e.g. 1 2 3 8 -5 ...)
Degree of B:
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:

rm tmp.txt
for i in range {0..5000}
    COUNT=`expr $COUNT + 1`
    echo $(($RANDOM%100 - 50)) >> tmp.txt
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 2
-30 50 <long line of numbers ...>

What am I doing wrong here?

share|improve this question

closed as too localized by Mat, jw013, jasonwryan, Chris Down, Caleb Nov 16 '12 at 9:05

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. If this question can be reworded to fit the rules in the help center, please edit the question.

What problems does the program have with the last line? –  choroba Nov 15 '12 at 8:30
It takes line that has 1 2 and parses it as number of A's and number of B's, instead of coefficients of A. It works if I do it by hand, but I need to test it on large amount of numbers. –  xerwin Nov 15 '12 at 8:39

Browse other questions tagged or ask your own question.