On macOS, in the zsh terminal, I ran the following commands:
cd /tmp
mkdir newdir
cd newdir
touch file1
./file1
The last command returned
zsh: permission denied: ./file1
But running
sh file1
executed the file with no errors.
I've read about how running sh filename
executes the file using the sh interpreter explicitly. The sh interpreter has additional permissions that allow it to run file1
.
However, I also read that ./file1
executes file1
using the default interpreter, in my case zsh
. So I tried to run
zsh file1
But this also executed the file without errors.
The question:
Why doesn't the interactive shell have permission to run the file, but at the same time has permission to execute using the interpreters sh, bash, zsh
?
Additionally, looking at the permissions of sh, bash, zsh
in the \bin
directory shows that the other
group has execute permissions on them:
-rwxr-xr-x 1 root wheel 1.3M Sep 16 16:28 zsh
-r-xr-xr-x 1 root wheel 1.2M Sep 16 16:28 bash
-rwxr-xr-x 1 root wheel 131K Sep 16 16:28 sh
Doesn't this mean any user can run any file using the interpreters which possess additional permissions?
chmod +x ./file1
before entering./file1
. There's a bit more info here.