#!/bin/sh printf 'Grock- ' read command while test "$command" != "quit" do case $command in setdb*) set $command if test $1 = "setdb" then if test $# -eq 1 then echo Missing Argument. else database=$2 if test ! -e $database then echo File $database does not exist. elif test ! -r $database then echo File $database is not readable. else cat $database | egrep '^[^ ]+[ ][^ ]+[ ][^ ]+$' | diff $database - > /dev/null if test $? = 0 then echo Database set to $database else echo Incorrect format in $database. echo The following lines were incorrectly formatted. cat $database | egrep -v '^[^ ]+[ ][^ ]+[ ][^ ]+$' database="" echo Database not set. fi fi if test $# -gt 2 then echo Extra arguments ignored. fi fi else echo Unrecognized command. fi ;; relnames) if test "X$database" = "X" then echo Database has not been set. else cat $database | cut -f1 -d" " | sort | uniq fi ;; entities) if test "X$database" = "X" then echo Database has not been set. else cat $database | cut -f2,3 -d" " | tr ' ' '\n' | sort | uniq fi ;; cardinality*) if test "X$database" = "X" then echo Database has not been set. else set $command if test $1 = "cardinality" then if test $# -eq 1 then echo Missing Argument. else shift relations=`cat $database | cut -f1 -d" " | sort | uniq` for relation in $* do echo "$relations" | grep "^$relation$" > /dev/null if test ! $? -eq 0 then echo Relation $relation does not exist. else echo $relation `cat $database | grep "^$relation" | wc -l` fi done fi else echo Unrecognized command. fi fi ;; *) echo Unrecognized command.;; esac printf 'Grock- ' read command done