<<< Date Index >>>     <<< Thread Index >>>

Re: [PATCH] when using `which` send errors to /dev/null



On Wed, May 23, 2007 at 01:33:56PM -0500, David Champion wrote:
> * On 2007.05.23, in <20070523180915.GB13547@xxxxxxxxxxxxxxxxxxxxxxxxx>,
> *     "Rado S" <list-rado@xxxxxx> wrote: 
> > =- Luciano Rocha wrote on Wed 23.May'07 at 18:48:01 +0100 -=
> > 
> > > when using `which` send errors to /dev/null
> > > {...}
> > > -if test -x "`which md5`"
> > > +if test -x "`which md5 2> /dev/null`"
> > 
> > On solaris 8 which produces noise on STDOUT, not STDERR.
> > Maybe the attached version suits all.
> 
> Is the problem with irregular behavior of different whiches?  Which is
> convenient but besides this has the drawback that since it's almost
> always a csh script, it sometimes returns csh aliases and such instead
> of what you really want.
> 
> It's easy enough to add a which-like command though.
> 

What about stopping to find where the binary is and check only if it can
be run?
if echo | md5sum &> /dev/null; then
  MD5=md5sum
elif echo | md5 &> /dev/null; then
  MD5=md5
elif echo | openssl md5 -hex &> /dev/null; then
  MD5="openssl md5 -hex"
else
  echo No md5 found 1>&2
  exit 1
fi

-- 
lfr
0/0

Attachment: pgpsBOPmaUftr.pgp
Description: PGP signature