xref: /titanic_41/usr/src/cmd/which/which.csh (revision 7ff178cd8db129d385d3177eb20744d3b6efc59b)
1#! /usr/bin/csh -f
2#
3# Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
4# Use is subject to license terms.
5#
6# Copyright (c) 1980 Regents of the University of California.
7# All rights reserved.  The Berkeley Software License Agreement
8# specifies the terms and conditions for redistribution.
9#
10#ident	"%Z%%M%	%I%	%E% SMI"
11#
12#       which : tells you which program you get
13#
14# Set prompt so .cshrc will think we're interactive and set aliases.
15# Save and restore path to prevent .cshrc from messing it up.
16set _which_saved_path_ = ( $path )
17set prompt = ""
18if ( -r ~/.cshrc && -f ~/.cshrc ) source ~/.cshrc
19set path = ( $_which_saved_path_ )
20unset prompt _which_saved_path_
21set noglob
22set exit_status = 0
23foreach arg ( $argv )
24    set alius = `alias $arg`
25    switch ( $#alius )
26        case 0 :
27            breaksw
28        case 1 :
29            set arg = $alius[1]
30            breaksw
31        default :
32            echo ${arg}: "      " aliased to $alius
33            continue
34    endsw
35    unset found
36    if ( "$arg:h" != "$arg:t" ) then		# head != tail, don't search
37        if ( -e $arg ) then			# just do simple lookup
38            echo $arg
39        else
40            echo $arg not found
41	    set exit_status = 1
42        endif
43        continue
44    else
45        foreach i ( $path )
46            if ( -x $i/$arg && ! -d $i/$arg ) then
47                echo $i/$arg
48                set found
49                break
50            endif
51        end
52    endif
53    if ( ! $?found ) then
54        echo no $arg in $path
55	set exit_status = 1
56    endif
57end
58
59exit ${exit_status}
60
61