As far as I understand, to make kernel execve a non-ELF file, the file must be a script started with a she-bang #!, but I have a script run successfully without it, why does this happen?

xtricman⚓ArchVirtual⏺️~🤐ls a.sh -l
-r-xr-xr-x 1 xtricman users 23 9月  26 18:45 a.sh
xtricman⚓ArchVirtual⏺️~🤐cat a.sh

This a.sh script doesn't contain a she-bang, so how does it run?

  • Your current shell interprets it. Sep 27 '18 at 1:31

If the file does not start with a "shebang" line, most shells will attempt to execute the lines in the file themselves.

  • Can I disable this behavior of bash? Sep 27 '18 at 2:07
  • 1
    The shell will only do this on files marked "executable". If you don't want to execute the file then remove the x flag (chmod a-x a.sh) Sep 27 '18 at 2:41

Not the answer you're looking for? Browse other questions tagged or ask your own question.