which/type & built-ins

Richard A. O'Keefe ok at quintus.UUCP
Wed Jan 3 11:02:48 AEST 1990


In article <1990Jan2.160927.11935 at usenet.ins.cwru.edu> chet at po.CWRU.Edu writes:
>In article <1297 at quintus.UUCP> ok at quintus.UUCP (Richard A. O'Keefe) writes:
>>...[in Bourne shell]...  So why does "type while" say "while not found"
>>rather than "while is a shell builtin"?

>Because `while' is a sh language construct (a statement), not a shell
>builtin.

Yes, I *KNOW* that.  That's an excellent argument for having "type while"
say "while is a keyword" rather than "while is a shell builtin".
It is *NOT* an argument for having "type while" say "while not found".
Given the wording of the manual page, and a few seconds thought about
what would be useful, it seems most natural to interpret the response
"XXX not found" as meaning "a command cannot currently begin with the
word XXX, so you can use XXX as the name of a new command without
interfering with anything".

That is, in fact, what I wanted to use 'type' and 'which' for.
I often make up little shell scripts, and I get so tired of calling
them all 'zabbo' and then forgetting what they do.  I would like to
put together a command "howabout X" which tells me if X is "free" in
both the Bourne shell and the C shell, and the obvious way to do that
is to check the output of both 'which $X' and 'sh -c "type $X"'.  It
looks as though the best I can do is to do that and then filter out
keywords myself, which means that I have to adapt "howabout" myself
for every UNIX system I deal with...

Recommendation:
    it would be a Good Thing if "which X" said
	#Cshell builtin X	# when X is a C-shell built-in command
	#Cshell keyword X	# when X is part of a C-shell control structure
    and "type X" said
	X is a keyword		# when X is part of a control structure
    so that
	no X in $PATH		# which
	X not found		# type
    would mean that X was not currently in use as the first word of a
    possible command.



More information about the Comp.unix.questions mailing list