2 # which - emulation of `which' as it appears in FreeBSD
4 # usage: which [-as] command [command...]
7 # Chet Ramey <chet.ramey@case.edu>
9 # Copyright 1999 Chester Ramey
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2, or (at your option)
16 # TThis program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write to the Free Software Foundation,
23 # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 local aflag sflag ES a opt
30 while builtin getopts as opt ; do
34 ?) echo "which: usage: which [-as] command [command ...]" >&2
39 (( $OPTIND > 1 )) && shift $(( $OPTIND - 1 ))
41 # without command arguments, exit with status 1
44 # exit status is 0 if all commands are found, 1 if any are not found
46 # if $command is a function, make sure we add -a so type
47 # will look in $PATH after finding the function
49 case "$(builtin type -t $command)" in
53 if [ -n "$sflag" ]; then
54 builtin type -p $a $command >/dev/null 2>&1
56 builtin type -p $a $command