Add a -s' flag for
silent' processing. Make the script return 0 for
success and 1 for failure. Describe the options in manpage.
This commit is contained in:
parent
f9a12a17c5
commit
153afc4dd2
@ -27,7 +27,7 @@
|
||||
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
.\" OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
.\"
|
||||
.\" $Id$
|
||||
.\" $Id: which.1,v 1.1 1995/01/26 21:49:48 jkh Exp $
|
||||
.Dd January 26, 1995
|
||||
.Dt WHICH 1
|
||||
.Os FreeBSD
|
||||
@ -36,12 +36,22 @@
|
||||
.Nd "locate a program file in the user's path"
|
||||
.Sh SYNOPSIS
|
||||
.Nm which
|
||||
.Op Fl as
|
||||
.Op Ar command
|
||||
.Ar ...
|
||||
.Sh DESCRIPTION
|
||||
.Nm Which
|
||||
takes a list of command names and searches the path for each executable
|
||||
file that would be run had these commands actually been invoked.
|
||||
.Pp
|
||||
The following options are available:
|
||||
.Bl -tag -width indent
|
||||
.It Fl a
|
||||
List all instances of executables found (instead of just the first one
|
||||
of each).
|
||||
.It Fl s
|
||||
No output, just return 0 if any of the executables are found, or 1 if
|
||||
none are found.
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Nm
|
||||
|
@ -31,22 +31,35 @@
|
||||
#
|
||||
# [whew!]
|
||||
#
|
||||
# $Id: which.sh,v 1.1.1.1 1995/01/25 19:18:33 jkh Exp $
|
||||
# $Id: which.pl,v 1.1 1995/01/26 21:49:54 jkh Exp $
|
||||
|
||||
$all = 0;
|
||||
$silent = 0;
|
||||
$found = 0;
|
||||
@path = split(/:/, $ENV{'PATH'});
|
||||
|
||||
if ($ARGV[0] eq "-a") {
|
||||
$all = 1; shift @ARGV;
|
||||
} elsif ($ARGV[0] eq "-s") {
|
||||
$silent = 1; shift @ARGV;
|
||||
} elsif ($ARGV[0] =~ /^-(h|help|\?)$/) {
|
||||
die "usage:\n\twhich [-a] program ...\n";
|
||||
die "usage:\n\twhich [-a] [-s] program ...\n";
|
||||
}
|
||||
|
||||
foreach $prog (@ARGV) {
|
||||
foreach $e (@path) {
|
||||
if (-x "$e/$prog") {
|
||||
print "$e/$prog\n";
|
||||
last unless $all;
|
||||
if (! $silent) {
|
||||
print "$e/$prog\n";
|
||||
}
|
||||
$found = 1;
|
||||
last unless $all;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($found) {
|
||||
exit 0;
|
||||
} else {
|
||||
exit 1;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user