# $Copyright:	$
# Copyright (c) 1984, 1985, 1986, 1987, 1988, 1989, 1990 
# Sequent Computer Systems, Inc.   All rights reserved.
#  
# This software is furnished under a license and may be used
# only in accordance with the terms of that license and with the
# inclusion of the above copyright notice.   This software may not
# be provided or otherwise made available to, or used by, any
# other person.  No title to or ownership of the software is
# hereby transferred.
#ident	"$Header: cmdsused 1.2 89/10/10 $@(#)sadmin:tools/cmdsused	1.2"
#	Find commands used in shell scripts.
#	Unclean and surely inaccurate mechanism attempts to parse the
#	script and extract the command names.

#!	chmod +x ${file}

trap "rm -f /tmp/$$cmdlist" 0

(
	ls /usr/bin
	ls /bin
	ls -ld /etc/*  |  sed -n '/^-[-r][-w]x/s/.* //p'
) >/tmp/$$cmdlist

cat $*  |
	tr '`;' '[\012*]'  |
	sed '
		s/exec[ 	]//
		s/^[ 	]*//
		s/[ 	][ 	]*#.*//
		/case[ 	]/,/[ 	]*esac/{
			/)$/d
		}
		/^cd[ 	]/d
		/^if[ 	]/d
		/^for[ 	]/d
		/^while[ 	]/d
		/^case[ 	]/d
		/^then[ 	]/d
		/^do[ 	]/d
		/^done[ 	]/d
		/^fi[ 	]/d
		/^esac[ 	]/d
		/^set[ 	]/d
		/^shift[ 	]/d
		/^then$/d
		/^do$/d
		/^done$/d
		/^fi$/d
		/^esac$/d
		/^set$/d
		/^shift$/d
		/^#/d
		'  |
	tr '|' '\012'  |
	sed '
		s/^[ 	]*//
		s/[ 	][ 	]*#.*//
		s/${[a-zA-Z0-9_:?+-]*}/ /g
		s/^[ 	]*[a-zA-Z0-9_-]*=[^ 	]*//g
		s/<<[^ 	]*//g
		s/[><]\{1,2\}[ 	]*[^ 	]*//g
		/^[!"'\''(){} 	]*$/d
		s/^[ 	]*//
		s;/bin/;;
		s;/usr/bin/;;
		/^xargs[ 	]/ {
			s///
			a\
xargs
		}
		s/[ 	].*//
	'  |
	sort -u  |
	fgrep -x -f /tmp/$$cmdlist
