On 1/10/21 10:49 AM, Ángel wrote:
On 2021-01-10 at 08:52 +0100, n952162 wrote:Hello,I consider it a bug that bash (and its hash functionality) includes non-executable files in its execution look-up and then (inevitably) simply reports an error, because its such files aren't executable. Perhaps it's there to support PATH look up for arguments to the bash command. That would also be a bug. Why should it be okay to execute a non-executable script? Supporting users who are too lazy to chmod a file ought to be less important than supporting users who want fine-grain control over what's executable and what's not.Hello I can't reproduce what you report. $ mkdir foo bar $ printf '#!/bin/sh\necho Program "$0"\n' > foo/program $ printf '#!/bin/sh\necho Program "$0"\n' > bar/program $ PATH="$PATH:$PWD/foo:$PWD/bar" $ chmod +x bar/program $ program It is executing bar/program, not foo/program which is earlier in the path, but not executable. Maybe you just made the earlier program not executable, and the old path is still being remembered? You should run hash -r after making executable changes that will make an already-executed command find a different program in the path (in the example above, making foo/program executable, or removing again its +x bit).
In the event only $PWD/foo is in PATH, bash fails to find *any* executable "program" command, and it then looks for non-executable forms.
$ (PATH="$PATH:$PWD/foo:$PWD/bar"; program) Program /tmp/bar/program $ (PATH="$PATH:$PWD/foo"; program) bash: /tmp/foo/program: Permission deniedThis is also the behavior of dash, zsh, and ksh, though only bash reported the entire pathname of the file without execute permissions.
dash: 2: program: Permission denied zsh: permission denied: program ksh: program: cannot execute [Permission denied]Hardly a bug in bash, merely a difference of opinion between the OP and the people who design shells.
-- Eli Schwartz Arch Linux Bug Wrangler and Trusted User
OpenPGP_signature
Description: OpenPGP digital signature