I can seem to run scripts (.sh) with and without them being set as executable. So where exactly this matters?
Let's say you have the file
If you make this file executable and run it with
and bash reads the file and executes the commands it contains.
Thus, for bash (or whatever interpreter your script requires) to "execute" the script, it only needs to be able to read the file.
So, for scripts, the execute bit just makes it a bit more convenient to execute it. As long as bash is executable, you can always run bash with the script file as argument, or run bash interactively and copy paste the script line by line into your terminal to have the commands executed.
Make sure you are not confusing "executing the shell script" with "run a shell script using sh".
This will not be affected by file permissions on
You are executing
File permissions will have effect if you really execute the script itself :
Note that file permissions are not supported by non-Linux filesystems, like FAT. So even if you run
Execute permission is enforced by the filesystem. But programs can "execute" the code too by reading the file contents, which bypasses filesystem permissions on "execute".
|show 1 more comment|
Don't think of it in the way that. Can I execute this file? Think of it in the way that: Who can execute this file?
I hope that helps.