Is Bash an interpreted language?

后端 未结 2 1674
谎友^
谎友^ 2021-02-07 07:39

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

  • it is not compiled into a lower format
  • every statement ends up ca
相关标签:
2条回答
  • 2021-02-07 07:53

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

    0 讨论(0)
  • 2021-02-07 08:06

    Bash is an interpreter according to the GNU Bash Reference Manual:

    Bash is the shell, or command language interpreter, for the GNU operating system.

    0 讨论(0)
提交回复
热议问题