How to link C / C ++ code to C-shell-script?

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

Now I have three different files - one C shell script

and 2 .c file

s.

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

Is there a better way to do this?

[I know that I can make one C code from these two ... but I will still be left with a shell script and C code. In fact, the two C codes have completely different things ... so I want them were separate]

+2


a source to share


4 answers


It sounds like you are concerned that your users are not diligent enough to figure out how to fix issues like bugs command not found

and the like. If you absolutely MUST hide the "complexity" of the collection of files, you can script other files. In most other cases, I would suggest that this approach will only increase your support workload, as semi-power users are less likely to learn how to eliminate this process.

If you choose to rely on a compiler on the system you are running on, you can save the C code as a set of commands cat $STRING >> file.c

to create two C files, which you then compile and use.



If you want to use precompiled programs, you can use the same basic process instead, except using xxd to generate the string in your script and reverse the conversion process to give you working binaries. Note: remember the chmod

binary so that it runs.

+3


a source


use the command shar

to create a self-extracting archive.

or better yet, use unzipsfx with the AUTORUN option.



This provides users with ONE file and only one command to execute (as opposed to one to turn and one to execute).

NOTE. The unzip command must use the -n option to run, so only the first run will extract files, and the next will skip the checkout.

+1


a source


Should I use a zip or tar file? And do you realize that .c files are not executable, you need to compile and link them first?

0


a source


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

#!/bin/bash

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

# compile
# execute

      

If you want to get fancy, you can check for the existence of the executable and skip compiling if they exist.

If you are programming a lot of commands, the rest of the Advanced Bash-Scripting Guide is worth checking out .

0


a source







All Articles