Printable Version of Topic

Click here to view this topic in its original format

Linuxhelp _ Programming in Linux _ shell script from c

Posted by: noobie Dec 10 2008, 08:41 AM

Hallo i am totally new with linux and i am trying to make a shell script for gaussian elimination.I have written the code in c because it is easier for me to understand.But i have some problems when trying to write it in a shell script.
here is the c code

#include <stdio.h>

int main()
        int n;
        float a[10][11],t;
    int i, j,k,max;

    for(i = 0; i < n; ++i)
        for (j = 0; j < n + 1; ++j)
            scanf("%f", &a[i][j]);

            for (i = 0; i < n; ++i)
                max = i;
                  for (j = i + 1; j < n; ++j)
                  if (a[j][i] > a[max][i])
                     max = j;

                 for (j = 0; j < n + 1; ++j)
            t = a[max][j];
            a[max][j] = a[i][j];
            a[i][j] = t;
        for (j = n; j >= i; --j)
            for (k = i + 1; k < n; ++k)
                a[k][j] -= a[k][i]/a[i][i] * a[i][j];

                                for (i = n - 1; i >= 0; --i) {
        a[i][n] = a[i][n] / a[i][i];
        a[i][i] = 1;
        for (j = i - 1; j >= 0; --j) {
            a[j][n] -= a[j][i] * a[i][n];
            a[j][i] = 0;
            for (i = 0; i < n; ++i) {
        for (j = 0; j < n + 1; ++j)
            printf("%.2f\t", a[i][j]);
    return 0;

i cannot find out how to create a table in my script for reading the matrix...
Any help appreciated...

Posted by: michaelk Dec 10 2008, 05:10 PM

AFAIK bash only supports one dimensional arrays. However I did find the following information.

Another limitation is bash can only perform integer math.

Obviously bash is extremely limited compared to c.

And here is a good link to bash scripting.

And why do you have to use bash? Homework assignment?

Posted by: noobie Dec 11 2008, 05:41 AM

Thanks a lot for your help...i did not know that bash supports only one dimension array...
It is a project for university and it counts 30% for the final grade for this lesson so i have to find a solution ...
I tried to use awk but i didnt figure out how to do it...
The time has come and i have to give the project until i guess i have to hurry....

Posted by: noobie Dec 17 2008, 03:57 PM

after a lot of trying and searching,i am sure now that i cannot do it using arrays..but how am i going to do it?does anyone has an idea of creating this script?
our deadline has moved to january so i have still the time to do this..

Posted by: michaelk Dec 17 2008, 07:29 PM

Most forums do not allow homework questions unless they ask specific questions.
At the moment I do not have any good ideas.

Posted by: edwardthompson Jan 6 2009, 04:45 AM

I think its a very poor script.

Where is the retention?

What happen with the writing in HD?. You have to be careful with your HD and the bigs databases.

And the bandwith? Why not use a temporal directory and make a synchronization to a final directory to save some of bandwith in the ftp connection? Or much more better.... why ftp?? you can save more time an bandwith if you make rsync

What happen with big databases? You spend more time, CPU and bandwith in make the dumps all hours and move it to the ftp that let the applications runs through db

I think that is a script that make the job but.... is very poor

Posted by: michaelk Jan 6 2009, 10:44 AM

I do not understand your post and how it relates to the OP questions.

Powered by Invision Power Board (
© Invision Power Services (