本文介绍了Bash:如何避免警告:此处XX行的文档以文件结尾定界(需要`EOM')的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个Linux主机(bash版本3.2.25(1))上运行了一个bash脚本,因为我已将该脚本移至另一台主机(bash verison版本4.2.25(1)),发出警告

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')

有问题的代码是:-(不确定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)

}

我确保EOM前后没有空格,制表符或任何特殊符号,因为这是在Google研究期间发现错误的原因.

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)调试的输出看起来像:-

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

这将提供一个script.sh,其中在其中一个函数中使用用法为:(但是我想这不是错误的原因,但可能是我错了)-

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}  
}  

请帮助并消除此警告,以及此EOM如何在此处正常工作?

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

推荐答案

在使用here文档时,请确保分隔符是该行中唯一的字符串.在您的情况下,右括号是单词的一部分,因此找不到匹配的定界符.您可以安全地将其移至下一行:

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
)

这篇关于Bash:如何避免警告:此处XX行的文档以文件结尾定界(需要`EOM')的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 05:55