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

Top Page

Reply to this message
Author: Richard Danter
Date:  
To: Hampshire LUG Discussion List
Subject: Re: [Hampshire] Checking command existence, host OS independent way..?
2009/4/6 Dominic Cleal <dominic@???>:
> 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.


Well, there I was thinking 'type' needed the full path, but it does
not. Looks like it will work, seems to on Linux and Solaris anyway.
Will have to do a test on *BSD too but looks good so far.

Thanks
Rich

--
http://radanter.deviantart.com/