
# Shell script to build a Prolog list of files in a directory

if [ $# != 3 ]   # check for correct no of args
then
  echo "usage: $0 directory pattern suffix"
  echo "sends a prolog list of atoms to standard output,"
  echo "containing all filesnames in directory which match pattern+suffix"
  echo "without suffix."
  exit 1
fi

cd $1

if [ "`ls $2$3 2> /dev/null`" != "" ]
then
  ls $2$3 | \
  sed -e '
s/^\(.*\)\'$3'$/,'"'"'\1'"'"'/
1 s/,/[/
$ s/$/]./
'

else
  echo '[].'
fi
