Are there any languages that compile to Bash?
Solution 1:
You could also try Batsh, which is a DSL (Domain-Specific Language) that compiles a C-syntax language to Bash (and Windows Batch).
- Project
- Online demo
Solution 2:
Since I originally asked this question, two projects have been released which attack this problem and do a pretty good job. Both reimplement many/most Unix tools in more programming-friendly runtimes.
Plumbum is implemented in Python and looks pretty solid:
http://plumbum.readthedocs.org/en/latest/index.html
ShellJS is implemented on Node.js and also looks pretty good:
https://github.com/arturadib/shelljs
Exciting developments! I'm looking forward to trying them out. If you already have, it'd be great to hear your experiences in the comments. Thanks!
Solution 3:
I tried all of the above (results) and started powscript.
Differences powscript vs the tools above
- extremely portable preprocessor (100% bash)
- balances between coffeescript and bash
- hasslefree portable all-in-one-file compiler/runtime, written in bash
- loose transpiler: inline bash always possible
Solution 4:
Bish is another option:
https://github.com/tdenniston/bish
Shell scripting with a modern feel.
Bish is a lightweight language created to bring shell scripting into the 21st century. It gives programmers the comfort of modern syntax but compiles to Bash, resulting in good portability (in as much as Bash is portable).
Solution 5:
The problem is that the whole strings-based semantics of Bash is so horribly broken, it'd be pretty difficult to do something like CoffeeScript for Bash.
Since you probably don't need function-level interoperability to call functions that are written in Bash, you're better off using something entirely different. Perl is close to Bash in being nasty and full of shortcuts and weird syntax, but its semantics are mostly sound. Python is less comfortable for things such as launching processes but is far better for general systems programming, clean and easy to maintain. Python has great libraries and modules for everything; Perl even better.