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

Top Page

Reply to this message
Author: Paul Stimpson
Date:  
To: Hampshire LUG Mailing List
Subject: Re: [Hampshire] Checking command existence, host OS independent way..?
Hi,

Could you pipe the result through a command like "grep $/" (the intent being only to pass on lines that begin with a "/" and therefore indicate a filename) ? Egrep might be more appropriate but I don't have a machine in front of me to do tests. 

Cheers,
Paul. 


Sent from my BlackBerry® wireless device

-----Original Message-----
From: Richard Danter <radanter@???>

Date: Tue, 7 Apr 2009 08:01:06 
To: Hampshire LUG Discussion List<hampshire@???>
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/

--
Please post to: Hampshire@???
Web Interface: https://mailman.lug.org.uk/mailman/listinfo/hampshire
LUG URL: http://www.hantslug.org.uk
--------------------------------------------------------------