How to determine if (executable) file is in path?

How to determine if (executable) file is in path?

Post by 55 » Sat, 01 Jan 1994 01:29:23



Any suggestions on how to determine if an filename is executable
(i.e., in a user's path) without manually stat'ing each path in the
shell path list?

No, the program must NOT be executed when performing this check.

I'm using csh and don't care about checking for shell aliases.

If only "if ( -x file ) ... " could be told to search the user's path as
well ...

Steve
--
-------------------------------------------------------------
Steve Maher                              (301) 286-5666 (voice)

NASA/Goddard Space Flight Center

 
 
 

How to determine if (executable) file is in path?

Post by Brian D » Sat, 01 Jan 1994 03:21:05



>Any suggestions on how to determine if an filename is executable
>(i.e., in a user's path) without manually stat'ing each path in the
>shell path list?
>No, the program must NOT be executed when performing this check.

On SunOS, try 'man 1 which'

NAME
     which - locate a command; display its pathname or alias

SYNOPSIS
     which [ filename ] ...

DESCRIPTION
     which takes a list of names and looks for  the  files  which
     would  be  executed  had these names been given as commands.
     Each argument is expanded if it is aliased, and searched for
     along the user's path.  Both aliases and path are taken from
     the user's .cshrc file.
                ^^^^^^
bd
--

Mission Software Development Division      Opinions are my own -
Huntsville, AL         (205) 461-4584      May be fatal if swallowed

 
 
 

How to determine if (executable) file is in path?

Post by Dan Horsfa » Sat, 01 Jan 1994 05:37:46





> >Any suggestions on how to determine if an filename is executable
> >(i.e., in a user's path) without manually stat'ing each path in the
> >shell path list?
>   [ ... ]
> On SunOS, try 'man 1 which'

> NAME
>      which - locate a command; display its pathname or alias

> SYNOPSIS
>      which [ filename ] ...

On all systems to which I have access, including SunOS,
   file `which which`    returns
   /usr/ucb/which   executable <shell> script

And, upon examining said script, one notes it manually stat's each path
in the path list.  Yes, "which" includes aliases; but it does _not_
use the _current_ path variable -- it uses _only_ the path established
in the users .cshrc file.  This could be seen as a limitation.

--
   Horse
                                      +    Metaphase Technology Inc
   Dan Horsfall    +1-612-482-4622    +    4201 Lexington Ave North      

   Fascinating fact: _Six_ American Presidents are _not_ buried in
                     the lower forty-eight states -- wow!

 
 
 

How to determine if (executable) file is in path?

Post by Leo Bickne » Sat, 01 Jan 1994 09:04:35



>On all systems to which I have access, including SunOS,
>   file `which which`    returns
>   /usr/ucb/which   executable <shell> script

>And, upon examining said script, one notes it manually stat's each path
>in the path list.  Yes, "which" includes aliases; but it does _not_
>use the _current_ path variable -- it uses _only_ the path established
>in the users .cshrc file.  This could be seen as a limitation.

        I would like to note two things:

        - tcsh (and, if I'm not mistaken zsh which I don't use)
          has a built in which command which is not only faster,
          but works as people expect.

        - /usr/ucb/which can be modified rather simply to use the
          current path.  The way my script is written if you don't have
          a ~/.cshrc it uses the current path.  If you don't run csh
          then it will be using your current path (since other
          shells use .tcshrc, .bashrc, .zshrc, .profile)

        Also of interest might be that the SCO SysV system I have
access to right now does not have a which command in any form.  I'm
going to have to compile tcsh on there I guess.

--




 
 
 

1. Executable Binary File vs. Executable Script File

Hi,

I need to write a simple script to "strip off" all the binary files in a
certain directory that contains some sort of executable script files,
i.e. perl, shell, tcl, etc.  I tried the following script that I named
"/tmp/junk":

        #!/bin/sh
        for ff in `find . -type f`
        do
                ! test -r $ff || strip $ff
        done

and it did stripped off the executable binary files as well as giving me
some error messages saying "File format not recognized" when it tried to
strip off the script files.  The question is: How to modify the above
script that will by pass the stripping process if the file is not really
an executable binary file?

Can anyone please help?  TIA.

--

PS> Remove the "4" from e-mail address to respond.

2. Linux META-FAQ

3. Determining differences in binary (executable) files

4. Pseudo device

5. paths & executable files

6. Promise Fast Wide SCSI board supported under Linux

7. Determining if a given path is a file system.

8. SMC EtherPower, Linux 1.2.8, de4x5.c

9. determine path of dlopen'd file?

10. determine throughput from LAN to Internet, Durchsatz vom LAN ins Internet berechnen

11. determine if executable failed?

12. determining the executable location

13. Determining version of AIX executable.