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

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

问题描述

我既喜欢又讨厌写Bash.我喜欢它 so 可以简化文件操作和处理流程(我同意

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中的双括号会失败regexp;有时是双分号,而其他则是单分号等等)

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

作为CoffeeScript的忠实粉丝,它可以编译为JS,我一直在想:是否有任何语言具有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天全站免登陆