which script

Dan Nicholson dbn.lists at gmail.com
Thu Nov 17 11:12:51 PST 2005


On 11/17/05, Jeremy Huntwork <jhuntwork at linuxfromscratch.org> wrote:
> Hi Guys:
>
> I have a question. The which script provided as an alternative to Gnu
> Which uses the syntax:
>
> type -pa | head -n 1 ...
>
> My question is, why do we pipe it through head so we can choose only the
> first occurence when 'type -path' does the same thing?

Preface: at work we have various older and newer servers, so I have a
variety of bash's to play with.

You seem to be right that type -path returns the first hit in your
path, so the head -n 1 is unnecessary.  -pa is backwards compatible to
-path -all.  Here's the results from my varied bash's.  (Systems are
HP-UX, RHEL3, and my own bash-3 built a la LFS.  Obviously, the bash's
on the systems could be patched, so this isn't definitive.)

HP-UX:
[dann at vente] echo $BASH_VERSION
1.14.2(2)
[dann at vente] type -path vi
/bin/vi
[dann at vente] type -path -all vi
/bin/vi
/usr/bin/vi
[dann at vente] type -p vi
/bin/vi
[dann at vente] type -pa vi
type: unknown option: pa
type: usage: type [-all | -path | -type ] name [name ...]

RHEL3:
[dann at nano] echo $BASH_VERSION
2.05b.0(1)-release
[dann at nano] type -path nano
/acct/dann/app/bin/nano
[dann at nano] type -path -all nano
/acct/dann/app/bin/nano
/usr/bin/nano
[dann at nano] type -p nano
/acct/dann/app/bin/nano
[dann at nano] type -pa nano
/acct/dann/app/bin/nano
/usr/bin/nano

Source compiled on RHEL3:
[11:07 AM dann at n006] echo $BASH_VERSION
3.00.16(1)-release
[11:07 AM dann at n006] type -path nano
/acct/dann/app/bin/nano
[11:07 AM dann at n006] type -path -all nano
/acct/dann/app/bin/nano
/usr/bin/nano
[11:07 AM dann at n006] type -p nano
/acct/dann/app/bin/nano
[11:07 AM dann at n006] type -pa nano
/acct/dann/app/bin/nano
/usr/bin/nano

> If it's a
> portability thing, that doesn't seem to make sense because we specify
> #!/bin/bash. Also, I don't know much of bash's history, so is it
> possibly because this is a new feature?

I don't know much about non-bash shells, but type with any of the
parameters -path -all -p -a did not work for sh or ksh on our Solaris
9 server.  So this seems to be needed as bash from my experience. 
Also, type -pa doesn't fly on old bash, but type -p does.

--
Dan



More information about the blfs-dev mailing list