Aseem Kishore Aseem Kishore - 1 month ago 13
Bash Question

Are there any languages that compile to Bash?

I both love and hate writing Bash. I love that it's so streamlined for operating on files and working with processes (I agree with this popular question that it's way better in this regard than Python, Ruby, etc.), but I hate the syntax, particularly around conditionals, loops, etc.

(This is subjective, but I find it both confusing and annoying. E.g.

when reading, but
when writing; writes silently fail if there are spaces around
; the double brackets in ifs when using regexp; double semicolons sometimes and single semicolons others; etc.)

As a huge fan of CoffeeScript, which compiles to JS, I've been wondering: are there any languages that have the aesthetic/syntax of languages like Python/Ruby/CoffeeScript but which compile and run as Bash instead of one of those other runtimes?

E.g. I'd love to be able to write mostly-Bash with just a bit simpler syntax:

$AGGREGATE_FILENAME = 'allfiles.txt'


for $file in files/*

switch $1
case 'test'
echo 'Tests finished!'
case 'deploy'
echo 'Packaging...'
mv foo bar/

This is a super contrived example, and the syntax is a strawman (mostly inspired from CoffeeScript but keeping the essential Bash notions of first-class commands, separated from variables, and loose typing).

Anyway, just a question and food for thought. I'd love to be able to write my scripts in something nicer than Bash. =) Thanks!


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:

ShellJS is implemented on Node.js and also looks pretty good:

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!