It does. And it does not. Can be complicated, I know.
The thing is, that script file itself isn’t actually executed as such. Not really.
It’s just a normal bash file whose contents gets read and passed on to an interpreter, which is actually just interpreting and executing the commands in the script. You can actually achieve what the script does in the command line. Not easily, no, but it can be done. Hence why I say the script itself doesn’t need to be executable.
If you want to run it by appending ./
in front of it, or perhaps some method I’m unaware of, you need to specify the shebang line, the first line, the one starting with #!
with the full path path to the interpreter.
For example, the following shebang will cause the file/scrippt to be read and exected by bash:
#!/usr/bin/bash
That will have the same effect as passing the script to bash in the terminal:
$ bash <fileName>
Where <fileName>
is the full path and filename of the script.
Also, as example,
#! /usr/bin/php
Will cause the file to be executed/run by the PHP interpreter.
And since the shebang starts with #
it is read as a comment by the interpreter and not executed itself. So the file that is marked as executable, and contains a shebang as well can still be passed to the bash interpreter, as in the above demonstration . However, if it doesn’t contain either the shebang or is set to executable, it cannot be run as an executable, by appending #!
or by another means.
My only guess as to why the file would only need 644
permissions to execute on startup is that it’s not executed itself, but rather by passing the script to thee interpreter.
Edit:
Also see The Code Enigma | The Code Enigma