Im two years on Linux and i'm still a newbie.
after reading: (thx to steeldriver
and Kamil Maciorowski)
What types of executable files exist on Linux?
Which shell interpreter runs a script with no shebang?
Does the shebang determine the shell which runs the script?
Difference between exec, execvp, execl, execv?
I now know, that when i execute a file in my shell, one of the c exec function is called and the kernel checks the file for magic numbers.
It also knows the shebang. It's like human readable magic numbers "#!".
If the shebang is detected, the kernel starts the interpreter given by path with the file as first argument.
If something went wrong (path missing or incorrect) or if the kernel doesnt recognize the file as executable defined in binfmt
, it throws an ENOEXEC error
.
But as i read, after the kernel throws the ENOEXEC error, there is a second try for execution.
The C exec function tries to execute the file with the Standard Shell Interpreter $SHELL
i dont want this, i want the reaction, like the file
command in linux tells me.
Is there an easy way to turn this off, without new compiling?
I) - For example, if i create a new file and enter a line
declare -p
.
The file command tells me: ASCII text
But what happens is on my system Linux Mint, that bash is started and
executes the line declare -p
I want to stop this. The kernel throws the ENOEXEC error, because a shebang is not found, and no other magic numbers for binary files defined in binefmt_
suit. But the second try is starting the file with Shell Standard interpreter on my system BASH
......................................................................................................
II). If i add the executable bits on a jpeg file,
the file command tells me
JPEG image data, Exif standard: [TIFF image data, little-endian, direntries=11, description=...
But what happens is on my system Linux Mint, that bash is started and writes
bash: ./aaa.jpg: cannot execute binary file: Exec format error
The kernel also throws an ENOEXEC error, but the second try is starting the file with Shell Standard interpreter on my system BASH
......................................................................................................
III) If i create a file "test" with executable bit set
echo $'\x7f\x45\x4c\x46\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00' >test
The file command tells me
test: ELF 64-bit LSB (Tru64)
But what happens is on my system Linux Mint is
./test: line 1: $'\177ELF\002\001\001': command not found
I think here the kernel also throws an ENOEXEC error, because i have only written the marker bytes and no executable code, and then again bash is started and try to execute the bytes as command name ..........................................................................
how can i stop this? Im on Linux Mint. If file command tells me, that this is a ASCII Text, then the kernel throws ENOEXEC error and i dont want further execution.