20

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?

codeforester
  • 39,467
  • 16
  • 112
  • 140
James Ko
  • 32,215
  • 30
  • 128
  • 239
  • 1
    Just to clarify - your question was prompted because you are not certain that a specific page on wikipedia can be relied on to be 100% complete and correct? – Greg Hewgill May 10 '15 at 20:35
  • 1
    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. – user2357112 May 10 '15 at 20:38
  • @GregHewgill Updated question to clarify. – James Ko May 10 '15 at 20:38
  • 3
    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? – Greg Hewgill May 10 '15 at 20:40
  • 3
    I'd post an answer just saying "Yes.", bit it would be rejected as too short. – Keith Thompson May 10 '15 at 20:41
  • 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. – ShellFish May 10 '15 at 20:43
  • 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. – Petr Skocik May 10 '15 at 20:43
  • 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. – Charles Duffy May 10 '15 at 21:16
  • 1
    @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. – Charles Duffy May 10 '15 at 21:20

3 Answers3

27

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

Keith Thompson
  • 254,901
  • 44
  • 429
  • 631
  • +1. Re: "There might possibly be some controversy over whether it's a *language*": Or perhaps *programming language*. For example, I think more people would accept that HTML is "interpreted" by the browser than would accept that it's an "interpreted language", because "interpreted language" implies "interpreted programming language", to the presumptive exclusion of markup languages. – ruakh May 11 '15 at 04:34
7

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

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

Bobulous
  • 12,967
  • 4
  • 37
  • 68
-2

This answer is complementary to Keith Thompson's answer, to which I'm leaving the immediate practical concerns.

In general I'd argue it's more useful to ask "how good is X as a language for Y purpose?" rather "should we classify X as Y type of language?" or "to what degree is X a language at all?".

Even without any of Bash's more advanced scripting features and "programming language -like" semantics, Bash is absolutely 100% a language, and so is any possible command line interface, and so is literally every interface, even physical ones. They might be languages which are so simple that you don't even have any mechanism to build an expression containing more than one term, but we can absolutely reason about them as if they were languages. Any input or action that a machine reacts to can be modeled as that machine "recognising" input "tokens", just like a finite state automaton or a Turing machine, and using that recognition to change some kind of internal state. "Pressing" some mechanical buttons might toggles their state permanently after you've stopped pressing them, while other buttons might require you to hold them down, and whatever thing they control reverts again when you release the button - they respond to that "release" input which the former buttons ignore. A rotary combination lock recognises certain inputs in serial; a bike lock is waiting to recognise certain inputs in parallel (which can be modeled serially). Bash happens to be in the Turing-complete class of languages, so by any objective measure it's as much a "programming language" as any other - the only interesting things we can say about it concern its design and ergonomics: "how easy is it to do things this way, or that way?"

Bash is a language; it's just a really shit one, because its syntax and semantics (evaluation rules) are inconsistent and needlessly complex, resulting from a combination of incompetence and trying to do two wildly different things with the same interface. Now we're all cursed with speaking its clumsy tongue as long as we're forced to reside in this inherited tower of band-aids and duct tape that is the modern computing stack.

iono
  • 2,575
  • 1
  • 28
  • 36
  • Damn, neckbeards get really mad when you criticise the badly-designed things they're invested in! Who'd have thought? – iono Jun 30 '23 at 14:36