#!/usr/bin/perl use Getopt::Long; my $progname= $0; # the name of this script $progname =~ s/^.*\///; # remove everything up to the last slash # Set default options sub usage { return " Usage: $progname \n\n" . " This shows the current path with one directory for each line.\n" . " If called with an executable, then it prints in order all\n" . " versions of that executable which are on the current path.\n" . " Options:\n" . " -h Print this message\n"; } my $help; GetOptions("h" => \$help, "help" => \$help); die usage() if ($help); my $exec= shift; my @pathlist= split(':',$ENV{"PATH"}); foreach (@pathlist) { if (defined($exec)) { print "$_/$exec\n" if (-x "$_/$exec"); } else { print "$_\n"; } }