Perhaps the question is what are the goals of this. They can be a subset of:
- The speed of interpreted scripts may be slower
- Maintaining health , maybe you have time that has more experience with C
- The flexibility of the script shows the limitations of what can be achieved with reasonable effort.
- Integration , perhaps you already have a code base that you are ready to integrate closely with scripts
- Portability
There are other reasons, such as scalability, efficiency, and possibly much more.
Based on the goals of "conversion", there are quite a few ways to achieve the C equivalent by varying the amount of code that will be "native". As an example, consider two extremes.
On the one hand, we have compiled C code that runs mostly like bash, so each line of the source script will generate code equivalent to the fork / exec / wait system calls, where the changes will basically do the equivalents of the wildcard extension, extract the values from environment variables, handle the synchronization of branched processes, as well as process pipelines with the corresponding system call.
Note that this βsimpleβ conversion is already a lot of work, which is likely to be worse than just writing another shell interpreter. In addition, it does not satisfy many of the above goals, since portability is wise, it still probably depends on system calls of the operating system and performance, only a gain from the initial command line parsing.
On the other hand, we have a complete census in more mode C. This will replace all conditional expressions with conditional expressions C, ls , cd and rm in the corresponding system calls and, possibly, replace string processing with the corresponding libraries.
It may be better in achieving some goals, but the cost is likely to be even greater than in the other case, also eliminating a lot of code reuse, as you will have to implement function equivalents to simple commands.
As for the tool to automate this, I don't know anyone, and if they are, they probably don't have widespread use, because converting bash to C or C to bash is probably not a good idea. If such a need arises, this is probably a symptom of a design problem, and therefore redesign is probably the best solution. Programming and scripting languages ββare different tools for different tasks, although there are areas of intersection between what can be done with them. Generally,
Don't script in C, and don't code in Bash
It is best to know how and when to use the tools that you have, then find a universal universal tool (for example, there are no such things as silver bullets).
Hope this helps a bit =)