Bug 1998 - `which' behaves different than the regular shell search
Summary: `which' behaves different than the regular shell search
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: which
Version: 6.0
Hardware: All
OS: Linux
Target Milestone: ---
Assignee: David Lawrence
QA Contact:
Depends On:
TreeView+ depends on / blocked
Reported: 1999-04-05 14:38 UTC by carlo
Modified: 2008-05-01 15:37 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Last Closed: 1999-04-06 16:31:01 UTC

Attachments (Terms of Use)

Description carlo 1999-04-05 14:38:43 UTC
The current which is a hack (look a the source).
It's main problem is that it returns directories
as if these are executable (because the execute mode bit
is set).  This gives problems in some cases and is
inconsistent with the documentation.

I am willing to rewrite `which', let me know where
to send the new tar.gz and rpm etc.

From current discussion with config.guess author:

Ben Elliston (bje@cygnus.com) wrote:
| > From: Carlo Wood <carlo@runaway.xs4all.nl>
| > Message-Id: <199903091509.QAA03972@jolan.ppro>
| > Subject: binutils bug: config.guess
| > when trying to compile binutils-, I ran
| > into a problem with config.guess.
| > I have "." in my PATH, and it seems that makes
| > config.guess fail to execute `ld'. It tries to execute
| > the directory ld/ in binutils.
| > I know I shouldn't have a "." in my path before
| > /usr/bin, but I am sure I am not the only one that
| > has it any way :).
| This is quite a specific case that causes this to fail.
| Since it only occurs when there is a subdirectory named
| `ld' (as there is in binutils) and then only when you
| have `.' in front of the path to your ld program, I
| am inclined to suggest a binutils-only modification to
| config.guess that just warns:
|       if test -d `which ld`
|         echo "Error: cannot invoke ld"
|       fi

It is actually a bug in `which' anyway.
The documentation of `which' claims:

       Which  takes a series of program names, and prints
       out the full pathname of the program that the shell
       would call to execute it. It does this by simulating
       the shells searching of the $PATH environment

But this is not correct in this case:

>mkdir ld
>which ld
>ld -V
GNU ld version 2.9.1 (with BFD
  Supported emulations:

`which' should skip anything that is not executable
and continue the search.  If fails to do that for
directories (maybe it only looks at the mode?).

I am going to write a new which that fixes that :/

 Carlo Wood  <carlo@runaway.xs4all.nl>

Comment 1 Jeff Johnson 1999-04-05 14:51:59 UTC
You can mail to me. Thanks for the report.

Comment 2 carlo 1999-04-06 16:01:59 UTC
Ok, I rewrote which.  Please get it from
if there are problems let me know.

The tar contains a working which-2.0.spec file.
I'll leave it to you create the rpms.

Please make sure to remove the alias for which in
 /etc/bashrc when you add it to the new RedHat release.

Thanks, Carlo.

Comment 3 Preston Brown 1999-04-06 16:30:59 UTC

I have added your wish to the distribution.  Thank you very much for
your contribution.

------- Email Received From  Carlo Wood <carlo@runaway.xs4all.nl> 05/20/99 06:12 -------

Note You need to log in before you can comment on or make changes to this bug.