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

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



On Wed, May 23, 2007 at 10:01:37PM +0200, Rado S wrote:
> =- Luciano Rocha wrote on Wed 23.May'07 at 20:22:32 +0100 -=
> 
> > > 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
> 
> You still put redirects for each test.
> With the {} capturing any future cases as well as localized
> deviations where the noise is sent (err-out) will be taken care of.

If you prefer { ... } 3>&2 &> /dev/null, then by all means. I,
personally, prefer the format I presented.

Anyway, the following is wrong:

 } >>/dev/null 2>&1 3>&2

As it sets stdout to /dev/null, stderr to stdout, and fd 3 to stderr,
that by now is /dev/null.

 } 3>&2 > /dev/null 2>&1 (or 3>&2 &> /dev/null) should work instead.

-- 
lfr
0/0

Attachment: pgpJAohmx59YY.pgp
Description: PGP signature