Blog coding and discussion of coding about JavaScript, PHP, CGI, general web building etc.

Thursday, March 31, 2016

Are there any languages that compile to Bash?

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. $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!

Answer by Miguel Prez for Are there any languages that compile to Bash?


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.

Answer by Jaromil for Are there any languages that compile to Bash?


You might want to give ZSh a try, it has a lot of improvements to make your shell script more readable.

http://www.zsh.org

Answer by Aseem Kishore for Are there any languages that compile to Bash?


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!

Answer by BYVoid for Are there any languages that compile to Bash?


You could also try Batsh, which is a DSL (Domain-Specific Language) that compiles a C-syntax language to Bash (and Windows Batch).

Answer by mweststrate for Are there any languages that compile to Bash?


You might want to take a look into nscript, in which you can write shell scripts using javascript. All the common bash constructions are in there, like exit codes, pipes, stream redirects, argument expansion, globbing, prompt etc.

Answer by masukomi for Are there any languages that compile to Bash?


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).

Answer by coderofsalvation for Are there any languages that compile to Bash?


I tried all of the above (results) and started powscript (beta).

Differences powscript vs the tools above

  • balance between coffeescript and bash
  • hasslefree portable all-in-one-file compiler/runtime, written in bash
  • loose transpiler: inline bash always possible


Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 72

0 comments:

Post a Comment

Popular Posts

Powered by Blogger.