1

The first line of any shell script must be the shebang line. The shebang line tells which interpreter should be used to execute the shell script.

But it seems there's some logic issue here:

  • If the shell script is not executed, it cannot be known which interpreter to use.
  • If it is unknown which interpreter to use, who should read the shebang line?

This looks like a chicken-egg problem.

Or is there some meta-interpreter?

Could anyone shed some light? Thanks.

smwikipedia
  • 1,203
  • 1
    "If it is unknown which interpreter to use, who should read the shebang line?" / "Or is there some meta-interpreter?" -- the operating system (kernel). In the same way it interprets binary executables. – ilkkachu Sep 19 '21 at 15:34
  • 1
  • 1
    dynamically linked ELF binaries also have an interpreter on Linux (not mentioned by the linked answers, but discussed in the LWN article linked from one of the answers). E.g. file /bin/ls shows something like /bin/ls: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2 ... – ilkkachu Sep 19 '21 at 16:01

0 Answers0