Is Bash an interpreted language? [closed]
Asked Answered
M

2

21

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?

Malvern answered 10/5, 2015 at 20:33 Comment(7)
This seems like the kind of question that starts arguments where everyone agrees about what's actually happening, but everyone has strong and conflicting opinions about how to define the terminology. I'd just try to avoid the topic.Gourmont
I think it's unequivocally true that bash is an interpreted language, but that's my opinion. Are you looking for references to back up that opinion?Seamanship
I'd post an answer just saying "Yes.", bit it would be rejected as too short.Remunerative
Yes I believe it is, since it's said that the she bang defines the interpreter, I think it's pretty safe to call bash an interpreted language.Covell
Yes, bash fits the definition. You definitely don't compile bash. The line between compile and interpreted can sometimes be a little blurry as you can have things like JIT, but I think meticulous pidgenholing starts to get ridiculous once you start to nitpick.Smallish
Your only reason to believe that bash wasn't interpreted was a question someone asked? Folks who ask such basic questions tend, by definition, to be unclear on the concepts.Calcimine
@ShellFish, well, that's not necessarily a defining factor -- there exist compiled languages you can invoke via an interpreter-style shebang which then compile the source given and run the resulting code. For that matter, tcc is a compiler that can do that for C. See also Clojure -- which has a REPL, but everything entered, even via that REPL, is compiled to Java classes before being invoked; shebang-based invocation for Clojure is likewise available.Calcimine
R
29

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

Remunerative answered 10/5, 2015 at 21:44 Comment(0)
K
9

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

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

Keane answered 10/5, 2015 at 20:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.