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. $var
when reading, but var
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' if not exists $AGGREGATE_FILENAME touch $AGGREGATE_FILENAME for $file in files/* cat $file >> $AGGREGATE_FILENAME switch $1 case 'test' run-tests echo 'Tests finished!' case 'deploy' echo 'Packaging...' mv foo bar/ deploy-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!
Bash is a powerful programming language, one perfectly designed for use on the command line and in shell scripts. This three-part series explores using Bash as a command-line interface (CLI) programming language.
It means C is a compiled language and Bash is an interpreted language.
Bash is an sh-compatible shell that incorporates useful features from the Korn shell (ksh) and C shell (csh). It is intended to conform to the IEEE POSIX P1003.
Besides being the superset to the Bourne shell syntax, Bash also includes features from other shell scripting languages such as KornShell (ksh) and C shell (csh) — for example, command-line editing and command history.
You could also try Batsh, which is a DSL (Domain-Specific Language) that compiles a C-syntax language to Bash (and Windows Batch).
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With