[Gllug] Detect if a program is available

Richard Jones rich at annexia.org
Thu Jul 26 13:06:01 UTC 2007


On Thu, Jul 26, 2007 at 01:17:08PM +0100, Tom Weissmann wrote:
> Is there a way to check that a program / executable is available, 
> without running it or using whereis or which?

Why the restriction on using 'which'?  In general if you want to check
if an executable is available, look at each element of $PATH in turn
and decide if the executable exists in that directory (you can go
further by checking for permissions).  That is basically what 'which'
does:

$ echo $PATH
/usr/lib64/qt-3.3/bin:/usr/kerberos/bin:/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/home/rjones/bin
$ strace which ls
[...]
stat("/usr/lib64/qt-3.3/bin/ls", 0x7fff9c2820d0) = -1 ENOENT (No such file or directory)
stat("/usr/kerberos/bin/ls", 0x7fff9c2820d0) = -1 ENOENT (No such file or directory)
stat("/usr/local/bin/ls", 0x7fff9c2820d0) = -1 ENOENT (No such file or directory)
stat("/usr/bin/ls", 0x7fff9c2820d0)     = -1 ENOENT (No such file or directory)
stat("/bin/ls", {st_mode=S_IFREG|0755, st_size=95056, ...}) = 0

The more general problem of "is package/library/program XX installed"
is usually solved in a Linux- or distro-specific manner.  Try looking
at the man pages for autoconf, pkg-config, rpm -q and dpkg -l.

> I have an Emacs function that depends on Cygwin netcat being installed, 
> and I'd like to it to check.

Ah ... Windows.  Well, I've written the above, might as well leave it
because it's good information.  Cygwin has a packaging system so
perhaps it's possible to query that.  You may be better off asking on
a Cygwin mailing list.

Rich.

-- 
Richard Jones
Red Hat
-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list