[net.sources] V8 'whatis' for ksh

arnold@emory.UUCP (Arnold D. Robbins {EUCC}) (05/02/86)

Here is a function that pretty much implements the V8 shell 'whatis' builtin
command. This command, for each argument, prints out what it is in relation to
the shell. For each argument, it prints it out in the same way one would type
it as input to the shell, for instance, functions as their definitions and
parameters as assignment to their values.

It is just something I felt like trying to do as a ksh function, more for
fun than anything else.  Enjoy.

------- cut here and put in your $ENV file, not a shar file ----------
# whatis --- ksh function to implement the V8 whatis builtin

# quote the ksh builtins to defeat aliasing

function whatis
{
	'typeset' i_ foo_	# local variables
	'typeset' -i var
	for i_ in $*
	do
		var=0
		if 'set' | grep "^${i_}=" > /dev/null
		then
			'set' | grep "^${i_}="
			var=1
		fi
		foo_="`'whence' -v ${i_}`"

		case "$foo_" in
		*built-in*)	'print' - builtin ${i_}
				;;
		*function*)	'typeset' -f ${i_}
				;;
		*exported*)	'print' - "alias -x '${i_}=${foo_##*alias for }"
				;;
		*tracked*)	'print' - "alias -t '${i_}=${foo_##*alias for }'"
				;;
		*alias*)	'print' - "alias '${i_}=${foo_##*alias for }'"
				;;
		*not\ found)	if ((! var))
				then
					'print' - "$foo_"
				fi
				;;
		*)		'print' - "${foo_##*is }"
				;;
		esac
	done
	return 0
}
-- 
Arnold Robbins
CSNET:	arnold@emory	BITNET:	arnold@emoryu1
ARPA:	arnold%emory.csnet@csnet-relay.arpa
UUCP:	{ akgua, decvax, gatech, sb1, sb6, sunatl }!emory!arnold

"All this digital stuff is just a fad. Analog is the way to go."
	-- William M. Robbins, 1984