3 ms·
The shell will NOT call the file command unless you type "file" and hit enter. Executables are executed by the kernel. They have the x bit set and a header tha
by LtWorf 4y ago
The shell will NOT call the file command unless you type "file" and hit enter.
Executables are executed by the kernel. They have the x bit set and a header that the kernel reads to decide what to do with them.
- IX-103 4y agoActually the header is read by the shell so it can call the appropriate loader. That may include running the file tool (or an internal equivalent that uses "database" of magic files).
- slabity 4y agoThat's completely incorrect. Where did you get that information from? A regular POSIX shell will simply call the `exec` syscall on the path provided. It may set up some environment variables or parse some arguments, but it will not actually read the file. In fact you can have a file with executable permissions, but not read permissions. The kernel determines how to execute the file based on its Magic Numbers, which are the first few bytes in certain file formats that will specify what type of file it is. It just so happens that the one for scripts are `#!`.
- GekkePrutser 4y agoI agree that I've simplified things a bit, 'file' is rather the user facing tool that does the same kind of inspection, and of course the X bit is a prerequisite. I know this but I didn't want to write a whole elaboration on my phone :) But my main point was that extensions aren't really a thing used at OS level to determine file type like on Windows, like the OP said.