Updates per shellcheck
Repairing here documents; adding quotes in sections intended to be executed by bash; exporting an unused (in this script) variable; adding [:lower:] etc to include locale variations, etc.
Repairing here documents; adding quotes in sections intended to be executed by bash; exporting an unused (in this script) variable; adding [:lower:] etc to include locale variations, etc.