1

I get a Delimter Error in a Shell Script:

#!/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

The result of the Script is fine. But I get two warnings:

./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

What is the problems here? Thank you!

Vlad Schnakovszki
  • 8,434
  • 6
  • 80
  • 114
eof
  • 13
  • 4

1 Answers1

1

You have the start of your here-doc inside of your command, but the EOF is outside of your command.

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
`

The ; seems wrong here too (at least it threw an error for me).

Gerald Schneider
  • 17,416
  • 9
  • 60
  • 78