linux - Bash 脚本警告 - HERE 文档由文件末尾分隔

标签 linux bash shell

<分区>

我有一个像下面这样的sql文件

#!/usr/bin/env bash

cat <<'VERBATIM_SQL'
INSERT INTO t_random VALUES (generate_series(1,9999999999), md5(random()::text));
VERBATIM_SQL

从 shell 脚本中调用 sql 文件如下所示

#!/usr/bin/env bash

./insert.sql | psql -U postgres -p 5432 -h localhost -d vnera
./insert.sql | psql -U postgres -p 5432 -h localhost -d vnera
./insert.sql | psql -U postgres -p 5432 -h localhost -d vnera

执行时我收到如下警告

Loop 1./insert.sql: line 5: warning: here-document at line 3 delimited by end-of-file (wanted `VERBATIM_SQL')

谁能告诉我为什么会出现此警告?

编辑

我按照其中一条评论中的建议做了

support@vrni-platform:~/postgres_junk$ dos2unix insert.sql
dos2unix: converting file insert.sql to Unix format ...

但仍然收到相同的警告

./insert.sql: line 5: warning: here-document at line 3 delimited by end-of-file (wanted `VERBATIM_SQL')

最佳答案

Shell 对他们将接受什么作为 here-doc 终止非常挑剔。它必须与提供的 token 精确匹配。特别是,您应该检查:

  • 终止行没有Windows行尾

  • 终止行上没有尾随空格。 (也不得缩进。)

关于linux - Bash 脚本警告 - HERE 文档由文件末尾分隔,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47497734/

相关文章:

Android NDK-arm-linux-androideabi-g++ : not found

c++ - 如何在 linux 中获取本地代码页?

git - 致命的 : open/dev/null or dup failed: No such file or directory

python - 在 Python 中实现类似 shell 的管道性能

linux - sh shell 下的数组(不是 bash)

linux - 如何将第一列中的文本附加到所有列 linux

bash - 如何运行一个在失败时不会退出直至成功的命令?

linux - 在 bash 脚本中将一个 IF 内的各种条件分组

当 shell 变量包含 & 符号时 MySql 查询失败

linux - 如何在 Bash 中模拟键盘按钮