C89cc.sh – standalone C89/ELF64 compiler in pure portable shell

c89cc.sh is an ambitious open-source project that compiles C89 code into x86-64 ELF64 binaries using only pure, portable shell script without any external dependencies.
In the world of programming, building a compiler usually requires low-level languages or complex toolchains. However, the c89cc.sh project by Alexandre Gomes Gaigalas breaks conventional rules by implementing a complete C89 compiler using only pure POSIX Shell script.
A Zero-Dependency Compiler
The most impressive aspect of c89cc.sh is its absolute independence. According to the source code, this compiler clears the PATH environment variable, meaning it does not call any external commands from the operating system. Every task—from parsing and string manipulation to binary generation—is handled by internal Shell functions.
The project supports the C89 standard and is capable of outputting ELF64 executables for the x86-64 architecture. This allows developers to compile C source code even on the most minimal systems, as long as a POSIX-compliant Shell interpreter is available.
High Compatibility and Portability
The author designed c89cc.sh to work seamlessly across various Shell environments such as bash, zsh, ksh, and yash. The source code includes compatibility layers to ensure commands like local or printf behave consistently across all platforms.
Key technical features integrated into this single script include:
- Advanced String Processing: Manually written functions for case conversion, string repetition, and Unicode handling.
- Detailed Error Management: An error reporting system capable of pinpointing the exact line and column of issues in the C source code.
- Built-in Standard Library (libc): Users have the option to use the included libc or skip it using the
--no-libcflag.
How It Works
Using c89cc.sh is extremely straightforward via the command line. Users simply pipe the C source code into the script and receive an executable file:
sh c89cc.sh < program.c > a.out
While writing a compiler in Shell Script might not offer the performance of GCC or Clang, c89cc.sh serves as a brilliant demonstration of the power of basic command-line tools. It is not only a fascinating engineering project but also a valuable educational resource for those wishing to dive deep into ELF file structures, parser mechanics, and the limits of Shell scripting.
Source: Hacker News











