Acronym lookup tool

Dave Sill de5 at ornl.gov
Wed Jan 30 06:42:37 AEST 1991


Disclaimer: provided without warranty as a public service.  Use at
your own risk.

Send comments/additions to de5 at ornl.gov.

--8<--cut-here----
#!/bin/sh
#
# NAME
#      whats - lookup acronym/abbreviation in database
#
# SYNOPSIS
#      whats [acronym [defn...]]
#
# DESCRIPTION
#      Whats, without any arguments, prompts for an acronym to look up.
#
#      With one argument, whats prints all entries from the database
#      that match the argument.  If no matches are found, whats
#      prompts for expansion of the acronym or abbreviation.
#
#      With more than one argument, whats scans the database for
#      entries matching the first argument.  If any matches are found,
#      whats prints the matching entries and asks if the remaining
#      arguments should be added as a new entry.  If no matches are
#      found, a new entry is created for the first argument with the
#      remaining arguments forming the expansion.
#
# FILES
#      acron or $ACRON
#
# BUGS/DEFICIENCIES
#      Not blindingly fast.
#      Not tested under System V.  (Uses "echo -n", "grep -i")
#
# AUTHOR
#      Dave Sill (dsill at nswc-oas.arpa) (de5 at ornl.gov as of 6/90)
#      Naval Surface Warfare Center (NSWC), Dahlgren, VA
#
n='-n'	# Use '' if your echo uses '\c'
c=''	# Use '\c' if your echo uses it
q='-i'	# Use '' or your grep's "ignore case" flag

if [ -z "$1" ]
then
    echo $n "What is what? $c"
    read ac
else
    ac=$1
fi
ac=`echo ${ac} | tr "[a-z]" "[A-Z]"`

if [ ! -f acron ]
then
    acron=${ACRON}
else
    acron=acron
fi
i=`grep $q -c "^${ac}	" ${acron}`

if [ -z "$2" -a $i -ne 0 ]
then
    # No definition passed and is on file, so just do a lookup.
    grep $q "^${ac}	" ${acron}
    exit
elif [ $i -ne 0 ]
then
    # Is on file and a definition was passed, check before adding.
    echo $i occurrences found.
    grep $q "^${ac}	" ${acron}
    echo $n "Still want to add ${ac}? $c"
    read reply
    if [ "${reply}" = n -o "${reply}" = N ]
    then
	exit
    fi
fi
if [ -z "$2" ]
then
    echo $n "What does ${ac} stand for? $c"
    read def
    if [ -z "${def}" ]
    then
	exit
    fi
else
    shift
    def=$*
fi
echo "${ac}	- ${def}" >>${acron}
echo "${ac}	- ${def}"
--8<--cut-here----

--
Dave Sill (de5 at ornl.gov)	  It will be a great day when our schools have
Martin Marietta Energy Systems    all the money they need and the Air Force
Workstation Support               has to hold a bake sale to buy a new bomber.



More information about the Alt.sources mailing list