Category: Utility Scripts
Author/Contact Info Randal L. Schwartz - merlyn
Description: Run this program (no arguments) and see which items in your PATH environment setting are shadowing later programs of the same name. This is an indication that you might get failures running the scripts of others, or perhaps if you ever rearrange your PATH.
    #!/usr/bin/perl -w
    use strict;

    my @path = split /:/, $ENV{PATH};
    my %path_inodes;
    my @clean_path;

    for (@path) {
      next unless m#^/#;
      my ($dev,$ino) = stat;
      next unless defined $dev;
      my $key = "$dev $ino";
      if (exists $path_inodes{$key}) {
        print "warning: $_ is linked to $path_inodes{$key}\n";
      $path_inodes{$key} = $_;
      push @clean_path, $_;

    my %progs;

    ## print "clean path is @clean_path\n";

    for my $dir (@clean_path) {
      use DirHandle;
      my @files =
        sort grep !/^\.\.?$/,
      ## print "$dir: @files\n";
      for my $file (@files) {
        if (exists $progs{$file}) {
          print "$file in $dir is shadowed by $progs{$file}\n";
        $progs{$file} = $dir;