How can you tell that what I told earlier is right if you're still trying to execute that C code as a shell script?
Let's try to make it more clear: the program you wrote is a C program and its suffix should be .c and not .sh.
C programs need to be compiled first
, using a C compiler (gcc is the most widespread one on Linux).
If your program is inside file program.c, then
gcc program.c -Wall -o program
will compile your code to the executable program
, if no errors occur (the -Wall flag makes the compiler print all warnings).
Your code is syntactically correct except for the
which should be
After the compilation completes successfully, you'll be able to run the program you just compiled with
Shell scripts are text files which are directly interpreted by the shell, so no compilation phase occurs.
This is an example shell script:
As you can see, the syntax is completely different from what you posted (no main, no includes, no ';' after instructions etc.).