#!/usr/local/rexx/rxx trace o /*=================================================================*/ /* whichdir */ /* */ /* Given any filename, find where it appears in the PATH. */ /* Return the name of the first directory in which it is found, */ /* or null if not found. */ /* */ /* Syntax: from command line-- */ /* whichdir (output to stdout) */ /* */ /* as a function-- */ /* xxx = whichdir() */ /* */ /* can be any type of file or directory name. */ /*=================================================================*/ parse arg searchfn parse source . dirhow . /* is this a command or a function? */ if searchfn = '' then do dir = '' call exit end path=getenv('PATH') do while path<>'' parse var path dir ':' path if chars(dir'/'searchfn)>0 then leave else dir='' end if dir = '.' then do call popen('pwd') parse pull dir end /****/ exit: /****/ /* Determine how to return the results */ select when dirhow = 'COMMAND' then do say dir exit end when dirhow = 'FUNCTION' then return dir when dirhow = 'SUBROUTINE' then return dir otherwise nop end exit