Compilers for shell scripts

后端 未结 3 487
梦毁少年i
梦毁少年i 2020-12-15 13:09

Do you know if there\'s any tool for compiling bash scripts?

It doesn\'t matter if that tool is just a translator (for example, something that converts a bash scrip

相关标签:
3条回答
  • 2020-12-15 13:23

    A Google search brings up CCsh, but it will set you back $50 per machine for a license.

    The documentation says that CCsh compiles Bourne Shell (not bash ...) scripts to C code and that it understands how to replicate the functionality of 50 odd standard commands avoiding the need to fork them.

    But CCsh is not open source, so if it doesn't do what you need (or expect) you won't be able to look at the source code to figure out why.

    0 讨论(0)
  • 2020-12-15 13:23

    I don't think you're going to find anything, because you can't really "compile" a shell script. You could write a simple script that converts all lines to calls to system(3), then "compile" that as a C program, but this wouldn't have a major performance boost over anything you're currently using, and might not handle variables correctly. Don't do this.

    The problem with "compiling" a shell script is that shell scripts just call external programs.

    0 讨论(0)
  • 2020-12-15 13:35

    In theory you could actually get a good performance boost.

    Think of all the

    if [ x"$MYVAR" == x"TheResult" ]; then echo "TheResult Happened" fi
    

    (note invocation of test, then echo, as well as the interpreting needed to be done.)

    which could be replaced by

    if ( !strcmp(myvar, "TheResult") ) printf("TheResult Happened");
    

    In C: no process launching, no having to do path searching. Lots of goodness.

    0 讨论(0)
提交回复
热议问题