Re: [PATCH] when using `which` send errors to /dev/null
* 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.
where ()
{
echo $PATH | tr : '\012' | while read dir; do
[ -x "$dir/$1" -a ! -d "$dir/$1" ] && echo "$dir/$1" && return 0
## "return 0" returns from the do/done subshell, not the
## function. "false" here ensures that a "where" that does not
## find the program returns false at end.
false
done
}
{ MD5=`where md5` } ||
{ MD5=`where md5sum` } ||
{ MD5=`where openssl` && MD5="$MD5 md5 -hex"; } ||
{ echo No md5 found.; exit 1; }
--
-D. dgc@xxxxxxxxxxxx, NSIT University of Chicago