I am new to Shell scripting. I wish to write a Unix script which will call a C program for N= 2^{i}, i= 1,2 ....20; and later record this data in a file.(This program calculates definite integral using trapezoid rule in C and returns iterative result and error for each term N.)While I just started learning C, I wrote my code for trapezoid rule:#include<stdio.h>#include<math.h>#define PI 3.14159265358979323846float fn(float x){   float integrand;  integrand = (1.0/(1.0+x*x));  return integrand;}int main(){  int i,N;  float a,b,sum=0,result=0,h;  float error;  printf(Enter the no of equally spaced points =);  scanf(%d,&N);  printf(Enter the lower limit=);  scanf(%f,&a);  printf(Enter the upper limit=);  scanf(%f,&b);  h=(b-a)/(N-1);  for(i=1;i<=N;i++)  {    sum=sum+fn(a+i*h);    result=(fn(a)+fn(b)+2*sum)*h/2;    error = fabs((atan(b)-atan(a))-result);    //error = PI/2.0 - result;    printf(N=%d result=%f error=%f\n, i, result, error);  }  printf(final result =%f\n, result);  printf(cumulative error =%f\n, error);}I execute this code bygcc -o err.o trap_error.c -lmand my gcc version is gcc (Ubuntu 5.4.0-6ubuntu1~16.04.2) 5.4.0 20160609I searched over Internet randomly, but didn't find useful info, I think I also have to modify my code too. If you just help me write the Unix script and later redirect the output in a .txt file. A Unix script with lines explained will be very helpful.
Writing a Unix shell script to call a C function and redirecting data to a .txt file
linux;shell script;shell;ubuntu;c
You're compiling and linking, so the output will be an executable, not and object file, which makes the .o suffix misleading.gcc -o err trap_error.c -lmmight be a better idea.It's not very clear what you're asking, but it looks like you're trying to feed it some auto-generated input and redirect all outputs to a file.You can generate N= 2^{i}, i= 1,2 ....20; in bash with:for ((i=2;i<2**20;i*=2)); do echo $i ; doneIf -1 and 1 are going to be your lower and upper limit respectively, then you can add those after $i, and pipe each such triple to an invocation of your program:for ((i=2;i<2**20;i*=2)); do echo $i -1 1 | ./err ; done > out.txtThe  > out.txt part will redirect all the outputs of all the ./err invocations into out.txt.