#!/bin/sh -e
#
# appendf - append string to end of a file, only if it is not already there

if [ -z "$1" ]; then
  printf '%s\n' "$(basename "$0") [string] <file>"
  exit 1
fi

string="$1"
file="$2"

if [ ! -f "${file}" ]; then
  echo "${string}" >>"${file}"
# grep -x/--line-regexp: force pattern to match only whole lines
elif ! grep -qx "${string}" "${file}"; then
  echo "${string}" >>"${file}"
fi

# pcre2grep -qM "${string}" "${file}" || echo "${string}" >>"${file}"
