1

我在 Shell 脚本中收到分隔符错误:

#!/bin/sh

result=`psql -d databasename -t -A <<EOF
SELECT COUNT(*) FROM schema.table
WHERE "column_name_x" = 'specific_value_x'
AND "column_name_y" = 'specific_value_y'
AND ("column_name_z" LIKE 'specific_z%' OR "column_name_za" LIKE 'specific_za%')
;`
EOF

echo $result
#EOF

脚本的结果很好。但我收到两个警告:

./filename.sh: line 13: warning: here-document at line 8 delimited by end-of-file (wanted `EOF')
./filename.sh: line 9: EOF: command not found

这里有什么问题?谢谢!

4

1 回答 1

1

您的命令中有 here-doc 的开头,但 EOF 在您的命令之外。

result=`psql -d databasename -t -A <<EOF
SELECT COUNT(*) FROM schema.table
WHERE "column_name_x" = 'specific_value_x'
AND "column_name_y" = 'specific_value_y'
AND ("column_name_z" LIKE 'specific_z%' OR "column_name_za" LIKE 'specific_za%')
EOF
`

这里;似乎也错了(至少它给我带来了错误)。

于 2014-09-24T08:29:59.347 回答