1

This question already has an answer here:

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
echo "FDHDSFHGFKJJHGO"
xtricman⚓ArchVirtual⏺️~🤐./a.sh
FDHDSFHGFKJJHGO

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

marked as duplicate by Kusalananda shell-script Sep 27 '18 at 4:17

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Your current shell interprets it. – Ipor Sircer Sep 27 '18 at 1:31
3

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) – Stephen Harris Sep 27 '18 at 2:41

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