[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: non-executable files in $PATH cause errors

From: L A Walsh
Subject: Re: non-executable files in $PATH cause errors
Date: Tue, 12 Jan 2021 22:19:38 -0800
User-agent: Thunderbird (Windows/20100228)

On 2021/01/09 23:52, n952162 wrote:

I consider it a bug that bash (and its hash functionality) includes
non-executable files in its execution look-up
But bash doesn't have an execution lookup.
It has a PATH lookup, and a completion lookup (for executables
when appropriate), but the closest thing to an execution
lookup might be "type -a" to look for how a command is executed.

In the completion lookup and in the execution lookup (type -a),
it only lists executable files.

 and then (inevitably)
simply reports an error, because its such files aren't  executable.
But it is not inevitable. Using 'cp' as an example.  Assuming
you have /usr/bin in your PATH, but ~/bin is in your PATH before
/usr/bin, then try:
"touch ~/bin/cp", then
"hash -u" (to clear the hash lookup), then type
"cp"<RETURN>, you will find that it returns the
value in /usr/bin, ignoring the non-executable file that was
first in your PATH.  So if an executable is in your PATH, it will
return that in preference to a non-executable.  Only when it can't
find an executable does it return the non-executable.

As for why this is useful?  Perhaps someone just created a
script script 'foo' in "~/bin", but forgot to toggle
the execution bit. Then they know that they forgot to
toggle the execution bit.

So it only reports the non-executable when there is no other
option -- not 'inevitably', which is useful because it reminds
people they need to toggle the 'x' bit.

Make sense?

reply via email to

[Prev in Thread] Current Thread [Next in Thread]