Amber: Write Clean Shell Scripts in a High-Level Language That Compiles to Bash
Let's be honest: writing complex shell scripts can feel like a pain. You start with good intentions, but soon you're wrestling with cryptic syntax, tricky quoting, and error handling that's more art than science. Bash is powerful, but it's not exactly developer-friendly for anything beyond a few lines.
That's where Amber comes in. It's a high-level programming language that compiles directly to Bash. You write cleaner, safer, more readable code—and it outputs a standard shell script that works anywhere Bash runs.
What It Does
Amber is a compiler. You write .ab files using a simple, modern syntax that looks familiar if you've used Python, Go, or TypeScript. Then you run the Amber compiler, and it produces a Bash script as output. You can run that output directly, or include it in your projects.
For example, here's a tiny Amber snippet:
let name = "World"
echo "Hello, $name!"
That compiles to proper Bash:
name="World"
echo "Hello, $name!"
Simple, right? But Amber handles much more than that—loops, functions, error handling, and even types.
Why It's Cool
1. No runtime dependencies. The output is pure Bash. No interpreter needed beyond what's already on virtually any Unix system. This is huge for deployment—you can compile on your dev machine and distribute the resulting script anywhere.
2. Safer by default. Amber prevents common Bash pitfalls. String interpolation is consistent. Variables are local by default. Functions return values cleanly. It catches errors at compile time that would be runtime surprises in raw Bash.
3. Modern syntax. Amber supports if/else, for loops, while loops, pattern matching, and operators that feel natural. Here's a quick example of a function:
fun greet(name: String) -> String {
return "Hello, $name!"
}
let message = greet("World")
echo $message
4. Type checking. Amber has basic types (String, Number, Bool, List, Map). You get compile-time type checking, which catches mismatches before they become runtime errors.
5. Clean output. The generated Bash is readable and maintainable. It's not obfuscated or minified. If you need to debug the raw shell script, you can still understand it.
How to Try It
Getting started takes about two minutes.
Install via Cargo:
cargo install amber
Or use the Docker image:
docker pull ph0enixkm/amber
Write your first script:
Create hello.ab:
let name = "Amber"
echo "Hello, $name!"
Compile and run:
amber hello.ab
# Outputs: Hello, Amber!
Or compile to a file:
amber hello.ab -o hello.sh
bash hello.sh
You can also check out the official docs for more examples and a full language reference.
Final Thoughts
Amber isn't trying to replace Bash for everything. If you're writing a simple alias or a quick one-liner, raw Bash is fine. But for scripts that grow beyond a few dozen lines—where you need functions, error handling, and maintainability—Amber is a refreshing upgrade.
The fact that it compiles to standard Bash means zero lock-in. You can always inspect the output, tweak it, or use it in environments where you can't install extra tools. It's a pragmatic, developer-friendly tool that makes shell scripting less painful without adding complexity.
If you've ever cursed at a shell script, give Amber a try. Your future self will thank you.
Follow us @githubprojects for more developer tools and open source finds.