Q:

Bash: How to avoid warning: here-document at line XX delimited by end-of-file (wanted `EOM')

I was a running a bash script fine on one of the linux host(bash version version 3.2.25(1)), since I have moved the script to another host (bash verison version 4.2.25(1)) it is throwing warning as
line 36: warning: here-document at line 30 delimited by end-of-file (wanted `EOM') (wanted `EOM')

The code in question is:-(not sure how EOM works)
USAGE=$(cat <<EOM
Usage:${BASENAME} [-h] [-n] [-q]
-h, --help        This usage message
-n, --dry-run     
-q, --quiet       
-d, --Destination 
EOM)

}
I have made sure there is no space, tab or any special symbols before and after EOM as it was cause of error find during research on google.
bash (bash -x) debugged output looks like:-
+ source /test/test1/script.sh
./test.sh: line 36: warning: here-document at line 30 delimited by end-of-file      
(wanted `EOM')
++ cat
+ USAGE='Usage:test [-h] [-n] [-q]
-h, --help        This usage message
-n, --dry-run     
-q, --quiet       
-d, --Destination

This is sourcing a script.sh where usage is used in one of the function as:
(However i guess this is not the cause of the error but may be I am wrong)-
show_usage()
{

declare -i rc=0
show_error "${@}"
rc=${?}
echo "${USAGE}"
exit ${rc}  
}  

Please help and getting rid of this warning and how this EOM working here exactly? 

A:

When using a here-document, make sure the delimiter is the only string on the line. In your case, the right parenthesis is taken as part of the word, so the matching delimiter is not found. You can safely move it to the next line:
USAGE=$(cat <<EOM
Usage:${BASENAME} [-h] [-n] [-q]
-h, --help        This usage message
-n, --dry-run     
-q, --quiet       
-d, --Destination 
EOM
)

A:

While this does not really answer you question, have you considered using read instead of cat?
read -d '' usage <<- EOF
Usage:${BASENAME} [-h] [-n] [-q]
-h, --help        This usage message
-n, --dry-run     
-q, --quiet       
-d, --Destination 
EOF

echo "$usage"

It reads the content of the here string into the variable usage, which you can then output using echo or printf.
The advantage is that read is a bash builtin and thus faster than cat (which is an external command).
You can also simply embed newlines in a string:
usage="Usage:${BASENAME} [-h] [-n] [-q]
-h, --help     This usage message
...
"

