Sometimes I need to understand which file, among the ones on my hard disk having the same name, is selected for a given task. A couple of example will better explain what I mean.
Just imagine you are compiling a C/C++ application and you want to know which "common.h" gets included among the many files with that name you have on your hard drive. Or, you are linking an application to library "common.lib" and you want to understand which file, among the many ones with that name, is selected by the linker. Or, last but not least, you run "find" but it doesn't do what it is expected to do and you want to know which of the many find.exe applications is getting executed.
These examples all fall into the more general problem of understanding which file is chosen when there is an environment variable that holds a list of directories (INCLUDE, LIB, PATH, and so on) where that file is to be searched for.
You can do it by hand by searching all directories (in the order they are in the environment variable) for the first occurrence of that file, or have a simple Perl script that does the job for you.
Just in case you don't feel like searching the file by hand (or you don't have time to write your own script) you can find it here. It's been developed on Windows but it should work on Linux/UNIX as well.
Here are some more information:
NAME search - search directories contained in an environment variable for files SYNOPSIS search options file ... Options: --var env. var. containing directories to be searched --help brief help message --man full documentation OPTIONS --var Environment variable containing a list of directories to be searched. --help Print a brief help message and exits. --man Prints the manual page and exits. DESCRIPTION This program will search directories contained in the environment variable specified for the given input file(s). Files appearing in more that one directory are printed in the order the directory appear in the environment variable. Example: C:\> search --var PATH grep.exe find.exe D:\wbin\grep.exe C:\WINDOWS\system32\find.exe D:\wbin\find.exe Directories contained in the environment variable must be separated through ';' on Windows system and ':' on UNIX systems.
You can download the script by clicking on the link in the "attachments" section below.