Bash是一种解释语言吗? [英] Is Bash an interpreted language?

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

问题描述

根据我到目前为止所读的内容,bash似乎符合解释语言的定义:

但是,我在维基百科的解释性语言页面上找不到bash的引用 ,或在Google上进行广泛搜索.我还在程序员堆栈上找到了页面交换似乎暗示bash不是一种解释语言-如果不是,那么它是什么?

解决方案

Bash肯定是解释的;我认为对此没有任何合理的问题.

关于它是否是语言可能存在一些争议.它主要设计用于交互使用,执行操作系统提供的命令.对于很多特定用途,如果您只是键入类似

的命令,

echo hello

cp foo.txt bar.txt

很容易认为这是执行简单命令的正当".从这个意义上讲,它与Perl和Python这样的解释语言有很大的不同,尽管它们可以交互使用,但主要用于编写脚本(解释程序). >

这种强调的一个结果是,其设计针对交互使用进行了优化.字符串不需要引号,大多数命令在输入后立即执行,您使用它执行的大多数操作将调用外部程序,而不是内置功能,等等.

但是我们知道,也可以使用bash编写脚本,并且bash具有很多功能,尤其是流控制结构,这些功能主要用于脚本中(尽管它们也可以在命令行中使用).

bash与许多脚本语言之间的另一个区别是bash脚本是按顺序读取,解析和执行的.在执行之前,不会检测到bash脚本中间的语法错误.相比之下,Perl或Python脚本在执行开始之前已被完全解析. (诸如eval之类的东西可以改变这一点,但是总体思路是正确的.)这是一个显着的差异,但是它并未标记出清晰的分界线.如果有的话,它会使Perl和Python更类似于编译语言.

底线:是的,bash是一种解释性语言.或者,也许更准确地说,bash是一种解释语言的解释器. (名称"bash"通常是指shell/解释器,而不是其解释的语言.)它与其他从一开始就被设计用于脚本编写的解释语言有一些显着差异,但是这些差异还不足以消除它们.它来自翻译语言"类别.

From what I've read so far, bash seems to fit the defintion of an interpreted language:

However, I could not find a reference to bash on Wikipedia's page for interpreted languages, or by extensive searches on Google. I've also found a page on Programmers Stack Exchange that seems to imply that bash is not an interpreted language- if it's not, then what is it?

解决方案

Bash is definitely interpreted; I don't think there's any reasonable question about that.

There might possibly be some controversy over whether it's a language. It's designed primarily for interactive use, executing commands provided by the operating system. For a lot of that particular kind of usage, if you're just typing commands like

echo hello

or

cp foo.txt bar.txt

it's easy to think that it's "just" for executing simple commands. In that sense, it's quite different from interpreted languages like Perl and Python which, though they can be used interactively, are mainly used for writing scripts (interpreted programs).

One consequence of this emphasis is that its design is optimized for interactive use. Strings don't require quotation marks, most commands are executed immediately after they're entered, most things you do with it will invoke external programs rather than built-in features, and so forth.

But as we know, it's also possible to write scripts using bash, and bash has a lot of features, particularly flow control constructs, that are primarily for use in scripts (though they can also be used on the command line).

Another distinction between bash and many scripting languages is that a bash script is read, parsed, and executed in order. A syntax error in the middle of a bash script won't be detected until execution reaches it. A Perl or Python script, by contrast, is parsed completely before execution begins. (Things like eval can change that, but the general idea is valid.) This is a significant difference, but it doesn't mark a sharp dividing line. If anything it makes Perl and Python more similar to compiled languages.

Bottom line: Yes, bash is an interpreted language. Or, perhaps more precisely, bash is an interpreter for an interpreted language. (The name "bash" usually refers to the shell/interpreter rather than to the language that it interprets.) It has some significant differences from other interpreted languages that were designed from the start for scripting, but those differences aren't enough to remove it from the category of "interpreted languages".

这篇关于Bash是一种解释语言吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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