# usage: trim_string "   example   string    "
trim_string() {
  # remove all leading white-space
  # '${1%%[![:space:]]*}': strip everything but leading white-space
  # '${1#${XXX}}':        remove white-space from start of the string
  trim=${1#"${1%%[![:space:]]*}"}

  # remove all trailing white-space
  # '${trim##*[![:space:]]}': strip everything but trailing white-space
  # '${trim%${XXX}}':         remove white-space from end of the string
  trim=${trim%"${trim##*[![:space:]]}"}

  printf '%s\n' "${trim}"
}
