Does bash use a VM or does it compile to machine code?

Viewed 72

I know that bash runs a file, by running its lines one by one. But I wan't to know exactly how does it do that, I am new to interpreters and still learning the ropes. How does it run its code, does it compile one line to bytecode and run it in a VM or does it compile to machine code, or something else entirely?

1 Answers

https://www.gnu.org/software/bash/manual/bash.html#What-is-a-shell_003f

At its base, a shell is simply a macro processor that executes commands. The term macro processor means functionality where text and symbols are expanded to create larger expressions.

A Unix shell is both a command interpreter and a programming language. As a command interpreter, the shell provides the user interface to the rich set of GNU utilities. The programming language features allow these utilities to be combined. Files containing commands can be created, and become commands themselves. These new commands have the same status as system commands in directories such as /bin, allowing users or groups to establish custom environments to automate their common tasks.

It's an interpreter but most programs you start from shell scripts are binaries.

The interpreter itself is written in C if that's what you're wondering. You can find the source code on https://git.savannah.gnu.org/cgit/bash.git/tree/

Related