Subject: Re: which(1) is a csh script?
To: Jesper Louis Andersen <email@example.com>
From: Greg A. Woods <firstname.lastname@example.org>
Date: 10/06/2003 18:43:48
[ On Monday, October 6, 2003 at 23:43:18 (+0200), Jesper Louis Andersen wrote: ]
> Subject: Re: which(1) is a csh script?
> I know that, but assume we are running off /bin/sh and only have
> a POSIX layer. Then what is correct portable way of getting something
> with the same semantics as which(1) or whence in ksh?
The "type" command is almost universally available in all shells
compatible with, or derived from, the original V7 Bourne Shell.
The only "widely" know exception I know about is the original "ash"
which was the basis for the 4.4BSD /bin/sh and indeed NetBSD's /bin/sh
didn't gain a "type" builtin until relatively recently.
I have for quite a long time used the following shell function to
imitate "type" on older systems that still have the original 4.4BSD
/bin/sh or where I might still use /bin/ash:
# .ashtype - This should be, but is not, a builtin in /bin/ash
# Copyright (c) Greg A. Woods 1996. All rights reserved.
# This software is not subject to any license of the American Telephone
# and Telegraph Company, the Regents of the University of California, or
# the Free Software Foundation.
# Permission is granted to anyone to use this software for any purpose on
# any computer system, and to alter it and redistribute it freely, subject
# to the following restrictions:
# 1. The authors are not responsible for the consequences of use of this
# software, no matter how awful, even if they arise from flaws in it.
# 2. The origin of this software must not be misrepresented, either by
# explicit claim or by omission. Since few users ever read sources,
# credits must appear in any relevant documentation.
# 3. Altered versions must be plainly marked as such, and must not be
# misrepresented as being the original software. Since few users
# ever read sources, credits must appear in any relevant documentation.
# 4. This notice may not be removed or altered.
#ident "@(#)HOME:.ashtype 26.2 03/03/22 15:50:15 (woods)"
if [ $# -ne 1 ] ; then
echo "Usage: type command" >&2
functions=`hash | grep "function $1\$"`
if [ -n "$functions" ] ; then
echo "$functions" | sed 's/^\([^ ]*\) \(.*\)$/\2 is a \1/'
case "$1" in
typeout="$1 is a builtin"
typeout="$1 not found"
for pathseg in $PATH
if [ -x $pathseg/$1 ] ; then
typeout="$1 is $pathseg/$1"
unset hashv pathseg typeout
Greg A. Woods
+1 416 218-0098 VE3TCP RoboHack <email@example.com>
Planix, Inc. <firstname.lastname@example.org> Secrets of the Weird <email@example.com>