Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compilers for shell scripts

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 script to a C program), as long as the translated result can be compiled.

I'm looking for something like shc (it's just an example -- I know that shc doesn't work as a compiler). Are there any other similar tools?

like image 828
mfriedman Avatar asked Aug 19 '09 00:08

mfriedman


People also ask

Which software is used for shell scripting?

This means that you need to use a text editor to create shell scripts. Some good command line text editors include vim, emacs, and nano. If you want to create shell scripts in a desktop environment using a graphical user interface, you can use text editors like Atom, Sublime Text, Notepad++, and Text Wrangler.

Which IDE is best for shell scripting?

IntelliJ IDEA provides coding assistance for shell script files: completion (including local paths), highlighting, quick documentation, textual rename refactoring, and more. It also includes a special type of run/debug configurations for shell scripts.

Does Bash have a compiler?

The Bash Shell Script Compiler converts shell scripts directly into binaries. Compiling your scripts provides protection against accidental changes, but you will have to contend with some quirks.


2 Answers

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.

like image 187
Stephen C Avatar answered Sep 24 '22 07:09

Stephen C


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.

like image 34
Chris Lutz Avatar answered Sep 21 '22 07:09

Chris Lutz