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

Top Page
Author: Dominic Cleal
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/.#lk0x577e4100.hantslug.org.uk.20121': Permission denied
gpg: keyblock resource '/var/lib/lurker/pubring.gpg': Permission denied
gpg: Signature made Mon Apr 6 18:18:25 2009 BST
gpg: using DSA key 7C7D326F2C2B72CC
gpg: Can't check signature: No public key
On Mon, 6 Apr 2009 17:56:30 +0100, Jon Fautley wrote:
> > [ -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?


'which' doesn't change its exit code. There's a comment here
suggesting why:
http://blogs.sun.com/moazam/entry/solaris_which_command_does_not

The suggestion to use 'type' builtin works well in sh/bash and dash here
on Sol10u3 and Debian - both returning a non-zero exit code.

--
Dominic Cleal
dominic@???