Re: [Hampshire] Checking command existence, host OS indepen…

Top Page
Author: Jon Fautley
Date:  
To: hampshire
Subject: Re: [Hampshire] Checking command existence, host OS independent way..?

Reply to this message
gpg: failed to create temporary file '/var/lib/lurker/.#lk0x5794a100.hantslug.org.uk.22491': Permission denied
gpg: keyblock resource '/var/lib/lurker/pubring.gpg': Permission denied
gpg: Signature made Mon Apr 6 17:56:33 2009 BST
gpg: using DSA key 9111B5743CA26D44
gpg: Can't check signature: No public key
On Mon, 06 Apr 2009 17:27:28 +0100
Richard Danter <radanter@???> wrote:

> Hi folks,
>
> I have been using a trivial test to discover if a command is available
> on a given host for some time as follows:
>
> [ -n "`which _command_`" ] && _do_something_with_command_
>
> This works perfectly on Linux, FreeBSD and NetBSD but not on Solaris.
>
> Sun decided it would be useful if "which" returned all the places it
> looked (i.e. your path) if it could not find what you were looking
> for. Since the result is now not an empty string the test fails to
> identify that the command was not found.


I don't have a slowaris box to check, but does which return a proper
status code on exit that you can check?

if which ls > /dev/null 2>&1; then
    do stuff
else
    yum install ls
done


Cheers,

/j
-- 
Jon Fautley RHCE, RHCDS, RHCX, RHCA  email: jfautley@???
Senior Consultant                    cell :     +44 7841 558683
Global Professional Services
Red Hat UK, 200 Fowler Avenue, Farnborough, Hampshire, GU14 7JP