有没有编译成 Bash 的语言? [英] Are there any languages that compile to Bash?

查看:24
本文介绍了有没有编译成 Bash 的语言?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我既喜欢又讨厌写 Bash.我喜欢它如此简化了文件操作和处理流程(我同意 这个流行的问题,它在这方面比 Python、Ruby 等要好得多),但我 讨厌em> 语法,尤其是在条件、循环等方面.

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.

(这是主观的,但我觉得它既令人困惑又烦人.例如,读取时是 $var,而写入时是 var;如果周围有空格,则写入会静默失败=;使用正则表达式时 ifs 中的双括号;有时使用双分号,有时使用单分号;等等)

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

作为可编译为 JS 的 CoffeeScript 的忠实粉丝,我一直在想:是否有任何语言具有 Python/Ruby/CoffeeScript 等语言的美学/语法,但可以作为 Bash 而不是其中之一编译和运行那些其他运行时?

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?

例如我希望能够用更简单的语法编写大部分 Bash:

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

这是一个超级人为的例子,语法是一个稻草人(主要受 CoffeeScript 启发,但保留了一流命令的基本 Bash 概念,与变量分离,以及松散的类型).

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

无论如何,只是一个问题和思考.我希望喜欢能够用比 Bash 更好的方式编写我的脚本.=) 谢谢!

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

推荐答案

自从我最初提出这个问题以来,已经发布了两个项目来解决这个问题并且做得很好.两者都在对编程更友好的运行时中重新实现了许多/大多数 Unix 工具.

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 是用 Python 实现的,看起来很可靠:

Plumbum is implemented in Python and looks pretty solid:

http://plumbum.readthedocs.org/en/latest/index.html

ShellJS 是在 Node.js 上实现的,看起来也不错:

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!

这篇关于有没有编译成 Bash 的语言?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆