Email address obfuscation in effect -- please
click here to turn it off.
[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
On Sat, 3 Nov 2007, Jonathan King wrote:
On 11/3/07, Mike Miller <EMAIL:PROTECTED> wrote:
Tell us if you remember because that was a good one. In tcsh, which I am
in the process of abandoning in favor of bash, you don't get that problem.
It always tells you correctly which command you are getting - alias,
builtin, etc. I thought bash could be configured to do this correctly,
but maybe I'm wrong.
I will check on that, but I am not optimistic.
Here's a really good clue:
http://www.unixguide.net/unix/bash/D1.shtml
The "type" command in bash, or "type -a" will do good things. Example on
with bash on Red Hat:
$ which which
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde --read-functions'
/usr/bin/which
$ which time
/usr/bin/time
$ type time
time is a shell keyword
$ type -a time
time is a shell keyword
time is /usr/bin/time
$ type which
which is aliased to `alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde --read-functions'
$ type -a which
which is aliased to `alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde --read-functions'
which is /usr/bin/which
$ type -a type
type is a shell builtin
From "man type" which is really a man page for all bash built-ins:
type [-aftpP] name [name ...]
With no options, indicate how each name would be interpreted if
used as a command name. If the -t option is used, type prints a
string which is one of alias, keyword, function, builtin, or
file if name is an alias, shell reserved word, function,
builtin, or disk file, respectively. If the name is not found,
then nothing is printed, and an exit status of false is
returned. If the -p option is used, type either returns the
name of the disk file that would be executed if name were speci-
fied as a command name, or nothing if ``type -t name'' would not
return file. The -P option forces a PATH search for each name,
even if ``type -t name'' would not return file. If a command is
hashed, -p and -P print the hashed value, not necessarily the
file that appears first in PATH. If the -a option is used, type
prints all of the places that contain an executable named name.
This includes aliases and functions, if and only if the -p
option is not also used. The table of hashed commands is not
consulted when using -a. The -f option suppresses shell func-
tion lookup, as with the command builtin. type returns true if
any of the arguments are found, false if none are found.
I can't find info on that right now. "man which" does give some
pointers on use of aliases for "which," but I don't know if that solves
this problem. "which" can definitely understand aliases but maybe not
shell built-ins.
If which isn't a built-in and I haven't lost all of my brain cells yet,
it just gets argc and argv, so it can't tell who called it, which means
it can't say to itself "ah; bash called me so I should point out that in
this case the user is likely to get a built-in for 'time'" If it were a
built-in, I think it could scan the names of the other built-ins and
figure this out.
You are probably right. tcsh's "which" is built-in:
which which
which: shell built-in command.
But the great thing is that bash's "type" command is built-in too and it
does what we need. All hail "type"!!
Mike
_______________________________________________
members mailing list
EMAIL:PROTECTED
http://mlug.missouri.edu/mailman/listinfo/members