#! /bin/ksh
# Quick fix for HPUX grep to allow the "-h" option which prevents output of
# filenames (C) RIK 1992
# NOTE: I do not recommend the use of this script outside of postgres,
#	get GNU grep instead.

# Some vars

ACTION=0		# Invoke sed
PARAMS=""		# Para list - may have to take out the "-h"
NUMFILES=-1		# Number of files on command line
GREP=/bin/grep		# Where is grep?
SED=/bin/sed		# Where is sed?
EXPR=/bin/expr		# Where for art thou expr?

# Check parameter list and take out the "-h" if necessary

for i in $*
do
	case "$i" in
		"-h")	ACTION=1 ;;
		-*)	PARAM="$PARAM $i" ;;
		*)	NUMFILES=`$EXPR $NUMFILES + 1`
			PARAM="$PARAM $i" ;;
	esac;
done;

# Do a standard grep or our "sedded" grep if necesary

if [ "$ACTION" = "0" ]
then
	$GREP $PARAM
else
	if [ "$NUMFILES" != "1" ]
	then
		$GREP $PARAM | $SED 's/[^:]*://'
	else
		$GREP $PARAM
	fi
fi
