Shebangs and executable text files, aka scripts
In Unix-like systems, a “script” is just an executable plaintext file. The operating system (often called “the kernel” in Linux) looks at the very first line to determine which interpreter to feed the file’s content into.
That first line is the so-called “shebang” (or hashbang), and it consists of a hash and an exclamation mark (#!
) character, followed by the path to the interpreter that is used to execute the file’s code. Here’s an example shebang line:
#!/usr/bin/env bash
When the kernels of Unix-like systems run a file with the executable bit set, they’ll take a look at the first bytes. This might contain a magic number. This number can be part of binary files or some human-readable character, like in the shebang. The kernel uses this information to know whether there is a proper way to execute it. This, for example, prevents situations where the kernel...