⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content

costowell/bashc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bashc

Backstory

The professor for my Compiler Construction course was giving a brief intro to compilation vs interpretation and said that Bash is pretty much a purely interpreted language. A great example of this is when Kyoto University in Japan lost 77TB of data because HP overwrote a backup script written in Bash while it was running. The language is so interpreted that modifications to it while its running can actually affect its behavior.

Because Bash is this purely interpreted language, I thought it would be kind of funny to go to the opposite end of the spectrum and write a compiler for it. What could this be used for and who would actually want to use this? Couldn't tell you!

Usage

Right now, its a complete mess. You need to have the bashc.h header file in the directory that you run the program so that the main.c file that gets generated can include it. To compile a script named script.sh, run:

cargo run --release -- ./script.sh

Internals

bashc embeds all binaries, all binaries' shared libraries, and the dynamic linker into an executable as data. It writes these files to memory-backed file descriptors, messes with the environment a little, and calls them how you would expect Bash would. Everything should work without any specific binary or library being present on the system since it should only rely on the embedded data.

bashc translates bash code to a C program which manages all of this.

Thoughts, opinions, and comments

  • "Wait, you just reinvented containers" - Anonymous Person
  • "Doesn't AppImage sort of do this?" - Rude Person

About

A compiler for bash

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published