xmlescape bash

xmlescape () {
    echo "$@" | sed 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g; s/"/\&quot;/g; s/'"'"'/\&#39;/g'
}

xmlescape "&"

should return

&amp;

https://stackoverflow.com/questions/12873682/short-way-to-escape-html-in-bash