How to bundle C/C++ code with C-shell-script?

By : Lazer

I have a C shell script that calls two C programs - one after the another with some file handling before, in-between and afterwards.

Now, as such I have three different files - one C shell script and 2 .c files.

I need to give this script to other users. The problem is that I have to distribute three files - which the users must keep in the same folder and then execute the script.

Is there some better way to do this?

[I know I can make one C code file out of those two... but I will still be left with a shell script and a C code. Actually, the two C codes do entirely different things... so I want them to be separate]

By : Lazer


Use a zip or tar file? And you do realize that .c files aren't executable, you need to compile & link them first?

You can include the c code inside the shell script as a here document:


cat > code.c << EOF
line #1
line #2

# compile
# execute

If you want to get fancy, you can test for the existence of the executable and skip compiling them if they exists.

If you are doing much shell programming, the rest of the Advanced Bash-Scripting Guide is worth looking at as well.

By : KeithB

use shar command to create self-extracting archive.

or better yet use unzipsfx with AUTORUN option.

This provides users with ONE file, and only ONE command to execute (as opposed to one for untarring and one for execution).

NOTE: The unzip command to run should use "-n" option, that way only the first run would extract the files and the subsequent would skip the extraction.

By : DVK

This video can help you solving your question :)
By: admin