6 ms·
Without a hashbang it's actually interpreted as machine code, it just doesn't have any machine instructions.
by ChristianBundy 12y ago
Without a hashbang it's actually interpreted as machine code, it just doesn't have any machine instructions.
- TazeTSchnitzel 12y agoInteresting that this works at all. Perhaps it's special-cased?
- delroth 12y agoNo, without a shebang it is interpreted as a shell script.
- bodyfour 12y agoCorrect. A file will only be considered a binary executable if it has a proper header (ELF, Mach-O, etc) The default if no header and no shebang is to treat it like a shell script. In fact, an empty executable file has been used to implement /bin/true on some old systems. Why take the added cost of a disk seek when just the information in the inode will do?
- TheSoftwareGuy 12y ago>In fact, an empty executable file has been used to implement /bin/true on some old systems. Why take the added cost of a disk seek when just the information in the inode will do? why is this only on old systems? it seems very efficient.
- TazeTSchnitzel 12y agoIt's not as efficient as it seems, as that means the shell is invoked.
- rspeer 12y agoWhat's more efficient is that most shells don't bother running /bin/true at all. "true" is just a shell builtin, so it doesn't need to spawn a process just to get an obvious return value out of it.
- fit2rule 12y agoFilesystems come and go. Not everyone has an executable bit.
- makomk 12y agoI think this may only work if the executable is run by the shell, at least on Linux. If I recall correctly using exec() to execute it directly won't work, and there's special fallback code in the shell itself to run executables with neither a header nor shebang as shell scripts. It's generally safest to include the shebang.
- Tuna-Fish 12y agoNo file on common unix platforms is interpreted directly as machine code. Machine code executables have headers which contain information on the environment needed, memory mappings, program entry points etc. Binary executables are not just immediately jumped into, they must be opened by a loader which will parse these headers and do the required work before continuing execution in the program itself. A zero-length binary fed into either ld.so (a.out loader) or ld-linux.so (elf loader) will not produce a zero-length output, but a parsing error.