Skip to main content
added 8 characters in body
Source Link
user10489
  • 11k
  • 1
  • 15
  • 37

To make an executable in unix, you make the file executable with chmod +x.

Of course, for this to work, the system has to know how to run it. If it's a text file, it might assume it is a shell script and run it with bash or sh.

But if you're doing it right, you would put at the top of your shell script

#!/bin/bash 

which explicitly tells unix that this file was meant to be interpreted with bash. Turns out you can put any binary name up there as long as it can take a text file as an input and either ignore the first line or ignore lines starting with #. You can do this, for instance, with perl, awk, python, etc...

You could consider the first two characters of the file (#!) to be a "magic number" identifying this as a script, with the path to the interpreter following that.

Linux took this a step further. It has a system (binfmt_misc) where you can describe arbitrary magic numbers for any executable format and rather than have the interpreter name in the file explicitly, you can assign an arbitrary interpreter to an arbitrary magic number identifier.

For instance, it is possible to identify java files and run them directly as if they were normal executables and have the system automatically invoke them with the java interpreter.

Turns out this is used even for normal executables. So if you say

$ file /bin/ls 

you might get

/bin/ls: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, stripped

/bin/ls: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, stripped

So the "interpreter" for a normal executable is /lib64/ld-linux-x86-64.so.2 (Side note: I don't think file knows about binfmt_misc, it has its own magic number database that includes a lot that binfmt_misc might not know.)

If you go ahead and install an emulator for another cpu, say qemu, it's not too difficult to just add the magic numbers to binfmt_misc for the executable formats qemu knows how to deal with, and then poof magically executables for that interpreter run as if they were native executables....just like shell scripts.

To make an executable in unix, you make the file executable with chmod +x.

Of course, for this to work, the system has to know how to run it. If it's a text file, it might assume it is a shell script and run it with bash or sh.

But if you're doing it right, you would put at the top of your shell script

#!/bin/bash 

which explicitly tells unix that this file was meant to be interpreted with bash. Turns out you can put any binary name up there as long as it can take a text file as an input and either ignore the first line or ignore lines starting with #. You can do this, for instance, with perl, awk, python, etc...

You could consider the first two characters of the file (#!) to be a "magic number" identifying this as a script, with the path to the interpreter following that.

Linux took this a step further. It has a system (binfmt_misc) where you can describe arbitrary magic numbers for any executable format and rather than have the interpreter name in the file explicitly, you can assign an arbitrary interpreter to an arbitrary magic number identifier.

For instance, it is possible to identify java files and run them directly as if they were normal executables and have the system automatically invoke them with the java interpreter.

Turns out this is used even for normal executables. So if you say

$ file /bin/ls 

you might get

/bin/ls: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, stripped

So the "interpreter" for a normal executable is /lib64/ld-linux-x86-64.so.2 (Side note: I don't think file knows about binfmt_misc, it has its own magic number database that includes a lot that binfmt_misc might not know.)

If you go ahead and install an emulator for another cpu, say qemu, it's not too difficult to just add the magic numbers to binfmt_misc for the executable formats qemu knows how to deal with, and then poof magically executables for that interpreter run as if they were native executables....just like shell scripts.

To make an executable in unix, you make the file executable with chmod +x.

Of course, for this to work, the system has to know how to run it. If it's a text file, it might assume it is a shell script and run it with bash or sh.

But if you're doing it right, you would put at the top of your shell script

#!/bin/bash 

which explicitly tells unix that this file was meant to be interpreted with bash. Turns out you can put any binary name up there as long as it can take a text file as an input and either ignore the first line or ignore lines starting with #. You can do this, for instance, with perl, awk, python, etc...

You could consider the first two characters of the file (#!) to be a "magic number" identifying this as a script, with the path to the interpreter following that.

Linux took this a step further. It has a system (binfmt_misc) where you can describe arbitrary magic numbers for any executable format and rather than have the interpreter name in the file explicitly, you can assign an arbitrary interpreter to an arbitrary magic number identifier.

For instance, it is possible to identify java files and run them directly as if they were normal executables and have the system automatically invoke them with the java interpreter.

Turns out this is used even for normal executables. So if you say

$ file /bin/ls 

you might get

/bin/ls: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, stripped

So the "interpreter" for a normal executable is /lib64/ld-linux-x86-64.so.2 (Side note: I don't think file knows about binfmt_misc, it has its own magic number database that includes a lot that binfmt_misc might not know.)

If you go ahead and install an emulator for another cpu, say qemu, it's not too difficult to just add the magic numbers to binfmt_misc for the executable formats qemu knows how to deal with, and then poof magically executables for that interpreter run as if they were native executables....just like shell scripts.

making this code makes it harder to read and makes my point missed. stop editing this.
Source Link
user10489
  • 11k
  • 1
  • 15
  • 37

To make an executable in unix, you make the file executable with chmod +x.

Of course, for this to work, the system has to know how to run it. If it's a text file, it might assume it is a shell script and run it with bash or sh.

But if you're doing it right, you would put at the top of your shell script

#!/bin/bash 

which explicitly tells unix that this file was meant to be interpreted with bash. Turns out you can put any binary name up there as long as it can take a text file as an input and either ignore the first line or ignore lines starting with #. You can do this, for instance, with perl, awk, python, etc...

You could consider the first two characters of the file (#!) to be a "magic number" identifying this as a script, with the path to the interpreter following that.

Linux took this a step further. It has a system (binfmt_misc) where you can describe arbitrary magic numbers for any executable format and rather than have the interpreter name in the file explicitly, you can assign an arbitrary interpreter to an arbitrary magic number identifier.

For instance, it is possible to identify java files and run them directly as if they were normal executables and have the system automatically invoke them with the java interpreter.

Turns out this is used even for normal executables. So if you say

$ file /bin/ls 

you might get

/bin/ls: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, stripped 

/bin/ls: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, stripped

So the "interpreter" for a normal executable is /lib64/ld-linux-x86-64.so.2 (Side note: I don't think file knows about binfmt_misc, it has its own magic number database that includes a lot that binfmt_misc might not know.)

If you go ahead and install an emulator for another cpu, say qemu, it's not too difficult to just add the magic numbers to binfmt_misc for the executable formats qemu knows how to deal with, and then poof magically executables for that interpreter run as if they were native executables....just like shell scripts.

To make an executable in unix, you make the file executable with chmod +x.

Of course, for this to work, the system has to know how to run it. If it's a text file, it might assume it is a shell script and run it with bash or sh.

But if you're doing it right, you would put at the top of your shell script

#!/bin/bash 

which explicitly tells unix that this file was meant to be interpreted with bash. Turns out you can put any binary name up there as long as it can take a text file as an input and either ignore the first line or ignore lines starting with #. You can do this, for instance, with perl, awk, python, etc...

You could consider the first two characters of the file (#!) to be a "magic number" identifying this as a script, with the path to the interpreter following that.

Linux took this a step further. It has a system (binfmt_misc) where you can describe arbitrary magic numbers for any executable format and rather than have the interpreter name in the file explicitly, you can assign an arbitrary interpreter to an arbitrary magic number identifier.

For instance, it is possible to identify java files and run them directly as if they were normal executables and have the system automatically invoke them with the java interpreter.

Turns out this is used even for normal executables. So if you say

$ file /bin/ls 

you might get

/bin/ls: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, stripped 

So the "interpreter" for a normal executable is /lib64/ld-linux-x86-64.so.2 (Side note: I don't think file knows about binfmt_misc, it has its own magic number database that includes a lot that binfmt_misc might not know.)

If you go ahead and install an emulator for another cpu, say qemu, it's not too difficult to just add the magic numbers to binfmt_misc for the executable formats qemu knows how to deal with, and then poof magically executables for that interpreter run as if they were native executables....just like shell scripts.

To make an executable in unix, you make the file executable with chmod +x.

Of course, for this to work, the system has to know how to run it. If it's a text file, it might assume it is a shell script and run it with bash or sh.

But if you're doing it right, you would put at the top of your shell script

#!/bin/bash 

which explicitly tells unix that this file was meant to be interpreted with bash. Turns out you can put any binary name up there as long as it can take a text file as an input and either ignore the first line or ignore lines starting with #. You can do this, for instance, with perl, awk, python, etc...

You could consider the first two characters of the file (#!) to be a "magic number" identifying this as a script, with the path to the interpreter following that.

Linux took this a step further. It has a system (binfmt_misc) where you can describe arbitrary magic numbers for any executable format and rather than have the interpreter name in the file explicitly, you can assign an arbitrary interpreter to an arbitrary magic number identifier.

For instance, it is possible to identify java files and run them directly as if they were normal executables and have the system automatically invoke them with the java interpreter.

Turns out this is used even for normal executables. So if you say

$ file /bin/ls 

you might get

/bin/ls: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, stripped

So the "interpreter" for a normal executable is /lib64/ld-linux-x86-64.so.2 (Side note: I don't think file knows about binfmt_misc, it has its own magic number database that includes a lot that binfmt_misc might not know.)

If you go ahead and install an emulator for another cpu, say qemu, it's not too difficult to just add the magic numbers to binfmt_misc for the executable formats qemu knows how to deal with, and then poof magically executables for that interpreter run as if they were native executables....just like shell scripts.

added 4 characters in body
Source Link
muru
  • 78.3k
  • 16
  • 213
  • 319

To make an executable in unix, you make the file executable with chmod +x.

Of course, for this to work, the system has to know how to run it. If it's a text file, it might assume it is a shell script and run it with bash or sh.

But if you're doing it right, you would put at the top of your shell script

#!/bin/bash 

which explicitly tells unix that this file was meant to be interpreted with bash. Turns out you can put any binary name up there as long as it can take a text file as an input and either ignore the first line or ignore lines starting with #. You can do this, for instance, with perl, awk, python, etc...

You could consider the first two characters of the file (#!) to be a "magic number" identifying this as a script, with the path to the interpreter following that.

Linux took this a step further. It has a system (binfmt_misc) where you can describe arbitrary magic numbers for any executable format and rather than have the interpreter name in the file explicitly, you can assign an arbitrary interpreter to an arbitrary magic number identifier.

For instance, it is possible to identify java files and run them directly as if they were normal executables and have the system automatically invoke them with the java interpreter.

Turns out this is used even for normal executables. So if you say

$ file /bin/ls 

you might get

/bin/ls: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, stripped

/bin/ls: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, stripped 

So the "interpreter" for a normal executable is /lib64/ld-linux-x86-64.so.2 (Side note: I don't think file knows about binfmt_misc, it has its own magic number database that includes a lot that binfmt_misc might not know.)

If you go ahead and install an emulator for another cpu, say qemu, it's not too difficult to just add the magic numbers to binfmt_misc for the executable formats qemu knows how to deal with, and then poof magically executables for that interpreter run as if they were native executables....just like shell scripts.

To make an executable in unix, you make the file executable with chmod +x.

Of course, for this to work, the system has to know how to run it. If it's a text file, it might assume it is a shell script and run it with bash or sh.

But if you're doing it right, you would put at the top of your shell script

#!/bin/bash 

which explicitly tells unix that this file was meant to be interpreted with bash. Turns out you can put any binary name up there as long as it can take a text file as an input and either ignore the first line or ignore lines starting with #. You can do this, for instance, with perl, awk, python, etc...

You could consider the first two characters of the file (#!) to be a "magic number" identifying this as a script, with the path to the interpreter following that.

Linux took this a step further. It has a system (binfmt_misc) where you can describe arbitrary magic numbers for any executable format and rather than have the interpreter name in the file explicitly, you can assign an arbitrary interpreter to an arbitrary magic number identifier.

For instance, it is possible to identify java files and run them directly as if they were normal executables and have the system automatically invoke them with the java interpreter.

Turns out this is used even for normal executables. So if you say

$ file /bin/ls 

you might get

/bin/ls: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, stripped

So the "interpreter" for a normal executable is /lib64/ld-linux-x86-64.so.2 (Side note: I don't think file knows about binfmt_misc, it has its own magic number database that includes a lot that binfmt_misc might not know.)

If you go ahead and install an emulator for another cpu, say qemu, it's not too difficult to just add the magic numbers to binfmt_misc for the executable formats qemu knows how to deal with, and then poof magically executables for that interpreter run as if they were native executables....just like shell scripts.

To make an executable in unix, you make the file executable with chmod +x.

Of course, for this to work, the system has to know how to run it. If it's a text file, it might assume it is a shell script and run it with bash or sh.

But if you're doing it right, you would put at the top of your shell script

#!/bin/bash 

which explicitly tells unix that this file was meant to be interpreted with bash. Turns out you can put any binary name up there as long as it can take a text file as an input and either ignore the first line or ignore lines starting with #. You can do this, for instance, with perl, awk, python, etc...

You could consider the first two characters of the file (#!) to be a "magic number" identifying this as a script, with the path to the interpreter following that.

Linux took this a step further. It has a system (binfmt_misc) where you can describe arbitrary magic numbers for any executable format and rather than have the interpreter name in the file explicitly, you can assign an arbitrary interpreter to an arbitrary magic number identifier.

For instance, it is possible to identify java files and run them directly as if they were normal executables and have the system automatically invoke them with the java interpreter.

Turns out this is used even for normal executables. So if you say

$ file /bin/ls 

you might get

/bin/ls: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, stripped 

So the "interpreter" for a normal executable is /lib64/ld-linux-x86-64.so.2 (Side note: I don't think file knows about binfmt_misc, it has its own magic number database that includes a lot that binfmt_misc might not know.)

If you go ahead and install an emulator for another cpu, say qemu, it's not too difficult to just add the magic numbers to binfmt_misc for the executable formats qemu knows how to deal with, and then poof magically executables for that interpreter run as if they were native executables....just like shell scripts.

added 1 character in body
Source Link
user10489
  • 11k
  • 1
  • 15
  • 37
Loading
Source Link
user10489
  • 11k
  • 1
  • 15
  • 37
Loading