I originally asked: On 27-Nov-01 Ted Harding wrote:
On 27-Nov-01 Alexandr Malusek wrote:
Note that the default "which" in SuSE is the bash alias
$ alias which alias which='type -p'
The old "which" command is still there:
$ /usr/bin/which ls /bin/ls
Would someone from SuSE please explain what the point of this particular alias is?
I've now had a look at a Red Hat 7.1 system. This also has
an alias for 'which':
RH> alias which='alias | /usr/bin/which \
--tty-only --read-alias --show-dot --show-tilde'
I *can* see the point of this. Consider "which <command>".
If there is an alias for <command>, this returns the alias
and also the path of the true executable used in the alias:
RH> alias ls
alias ls='ls --color=tty'
RH> which ls
alias ls='ls --color=tty'
/bin/ls
RH> which which
alias which='alias | /usr/bin/which --tty-only \
--read-alias --show-dot --show-tilde'
/usr/bin/which
This is fine; you get both -- both 'alias' and standard 'which'.
If there is no alias, you just get the usual behaviour of the
standard 'which'. So you lose nothing, and gain on the aliases.
One the other hand, SuSE has
SuSE> alias which
alias which='type -p'
And, of course, since 'ls' (and also 'which' and a lot of other
things) have aliases, 'type -p' in bash returns nothing:
SuSE> which ls
SuSE> which which
SuSE> which dir
...
NOW:
SuSE> type -t ls
alias
and ["help type"]:
If the -p flag is used, `type' either returns the name of the disk
file that would be executed, or nothing if `type -t NAME' would not
return `file'.
which is why SuSE 'which' returns nothing for aliases, including 'ls'.
However ["help type"]:
If the -a flag is used, `type' displays all of the places that contain
an executable named `file'. This includes aliases and functions, if
and only if the -p flag is not also used.
and indeed:
SuSE> type -a ls
ls is aliased to `ls $LS_OPTIONS'
ls is /bin/ls
SuSE> type -ap ls
/bin/ls
So I *guess* that SuSE either intended
alias which='type -a'
(which is effectively the same behaviour as in Red Hat, though
differently achieved); or else:
alias which='type -p'
which just gives you the path to the executable and not the alias.
Either way, it looks as though the SuSE alias for 'which'
is a mistake.
Ted.
--------------------------------------------------------------------
E-Mail: (Ted Harding)