The script was apparently edited on a Windows machine, which uses CRLF as the line endings, instead of Unix's LF. You need to remove those extraneous CR characters. If you have the dos2unix
program, use it, otherwise:
tr -d '\r' < mxpost > mxpost.fixed
mv mxpost.fixed mxpost