Subject: bin/4872: Added feature for 'which'
To: None <gnats-bugs@gnats.netbsd.org>
From: None <bgrayson@ece.utexas.edu>
List: netbsd-bugs
Date: 01/22/1998 12:43:58
>Number:         4872
>Category:       bin
>Synopsis:       Add -a option to which, to show _all_ matches
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Thu Jan 22 10:50:00 1998
>Last-Modified:
>Originator:     Brian Grayson
>Organization:
	Parallel and Distributed Systems
	Electrical and Computer Engineering
	The University of Texas at Austin
>Release:        Jan. 1998
>Environment:
NetBSD marvin 1.3_BETA NetBSD 1.3_BETA (MARVIN) #25: Sun Dec 28 11:54:44 CST 1997     bgrayson@marvin:/a/c3p0/home/c3p0/src/sys/arch/i386/compile/MARVIN i386

>Description:
	For years, I have used a modified `which' script which
	lists _all_ matching executables, instead of just the
	first one.  This is handy when one wonders if
	there are two versions of, say, gcc installed, and you
	want to check which one is being used.

	With the following patch, a flag of -a to `which' will tell
	it to _not_ stop at the first match.

	As an example, on one of our machines, we haven't cleared
	out the stale dump* executables in /usr/sbin.
	% which dumpfs
	/usr/sbin/dumpfs

	% which -a dumpfs
	/usr/sbin/dumpfs
	/sbin/dumpfs

	As it turns out, the second one is the more recent one,
	and should be used.

	Note that if a path component is duplicated, the -a flag
	will print out duplicates.  I don't think there's an easy
	csh fix for this.
	% set path = ($path /usr/bin /usr/bin)
	% which -a gcc
	/usr/bin/gcc
	/usr/bin/gcc
	/usr/bin/gcc

	I have found this to be a very useful feature for quite
	some time, but I'm not sure if there are compatibility
	reasons for not adding such functionality to `which.'
	
>How-To-Repeat:
	
>Fix:
--- /usr/bin/which      Tue May  6 07:46:06 1997
+++ which       Thu Jan 22 12:11:40 1998
@@ -40,6 +40,11 @@
 #
 set prompt = "% "
 set noglob
+unset keepgoing
+if ( $1 == "-a" ) then
+  set keepgoing=1
+  shift
+endif
 foreach arg ( $argv )
     set alius = `alias $arg`
     switch ( $#alius )
@@ -65,7 +71,7 @@
            if ( -x $i/$arg && ! -d $i/$arg ) then
                echo $i/$arg
                set found
-               break
+               if ( ! $?keepgoing) break
            endif
        end
     endif
	
>Audit-Trail:
>Unformatted: