A script that compiles a C file and creates an executable

Danielnzau
Mar 17, 2023

--

This will be the simplest concept that we will cover, as we will only be compiling and redirecting the executable file.

We will use gcc alone with out any options, this is because the source code will be undergoing all the 4 steps of compilation.

gcc source_code_file

The above code compiles the source code and makes it executable.

Now that we have an understanding of the concept, how about we solve a problem

/**
*Write a script that compiles a C file and creates an executable named cisfun.

* The C file name will be saved in the variable $CFILE
*/

The above question asks that we compile $CFILE and store the result in cisfun this should be easy, don’t you agree?

#!/bin/bash
gcc $CFILE -o cisfun

I hope you learned something.

--

--