Ensuring executed script’s parent directories permissions in Unix-like systems
I’ve recently discovered that it’s not sufficient enough to grant +x permission to a script in order to make it executable. Besides that you have to check if script’s parent directories also have execution rights. But it depends on how you call the script.
If you use absolute path, than all the parent directories up to the one in root folder will be checked for having execution rights.
; If you execute the following script, directories "path", "to" and "my" should have execution rights /path/to/my/script.sh
If you use relative path, than you should grant execution rights to all the directories mentioned in the script’s path. Actually this rule applied to absolute path too.
; Here execution rights are checked for "to" and "my" directories only cd /path to/my/script.sh ; This scenario is the same as absolute path - .. refers to "path" folder, so it need to have execution rights here as well cd /path ../to/my/script.sh
So, summarizing it I would put the rule here again.
If a script is being executed in Unix-like system, all the parent directories mentioned in the script path have to have execution rights.