Dec 18, 2000, 11:29 PM
Post #5 of 6
(1802 views)
Permalink
On Mon, Dec 18, 2000 at 09:18:44PM +0100, Sven Sunder wrote:
> On Mon, 18 Dec 2000, you wrote:
>
> > > + if ! which $NAME 1>/dev/null ; then
>
> > I think you are wrong for this one. Give a try to CVS and let me know
> >
> > It must work. Otherwise I think
> >
> > + if [ ! "`which $NAME 2>/dev/null`" ]; then
> >
> > would be better ..
> >
>
> Hi,
>
> hmm I think I was right, lets see ...
>
> sunder2:~$ NAME=fuser; `which $NAME`
> usage: fuser [ -a | -s ] [ -n space ] [ -signal ] [ -kimuv ] name ...
>
> [snip, this is the normal usage information]
>
> Fine, if the command is there, there's no problem, but
>
> sunder2:~$ NAME=foobar; `which $NAME`
> bash: which:: command not found
>
> This is the error the surrounding test command cant handle, in contrast:
> sunder2:~$ NAME=foobar; which $NAME
> which: no foobar in ([searchpath])
>
> will result in exitcode 1 which will be handled correctly by the normal if
> statement.
>
> Why do you think it should be necessary to execute the command the "which"
> found ?
>
> And, last :
> sunder2:~$ NAME=foobar; if [ ! "`which $NAME 2>/dev/null`" ]; then echo "no"; else echo "yes"; fi
> yes
> sunder2:~$ NAME=fuser; if [ ! "`which $NAME 2>/dev/null`" ]; then echo "no"; else echo "yes"; fi
> yes
> sunder2:~$ NAME=foobar; if [ ! `which $NAME 2>/dev/null` ]; then echo "no"; else echo "yes"; fi
> [.: too many arguments
> yes
> sunder2:~$ NAME=fuser; if [ ! `which $NAME 2>/dev/null` ]; then echo "no"; else echo "yes"; fi
> yes
>
> sunder2:~$ NAME=foobar; if ! which "$NAME" 1>/dev/null; then echo "no"; else echo "yes"; fi
> no
> sunder2:~$ NAME=fuser; if ! which "$NAME" 1>/dev/null; then echo "no"; else echo "yes"; fi
> yes
>
> I think my solution leads to the expected answer, didn't ist ?
>
> Bye,
> Sven
You are both scaring me. I don't think "which" is a good idea at all, not
least because it is confusing.
First, in many systems which is redefined for you as something other than
what you expect, that is, is it "/usr/bin/which" or is it "type -p".
Second, root should not be running tools that depend on path overmuch. There
are only so many places fuser could be, just use "[ -x /bin/fuser ]" which
avoids path problems.
-dg
--
David Gould dg@example.com
SuSE, Inc., 580 2cd St. #210, Oakland, CA 94607 510.628.3380
why would you want to own /dev/null? "ooo! ooo! look! i stole nothing!
i'm the thief of nihilism! i'm the new god of zen monks."