3

I'm simply trying to get the output from a sql statement and store in bash variable. I am getting " unexpected EOF while looking for matching `)' " error. I don't see what i'm doing wrong. Why am I getting this error?

var=$($ORACLE_HOME/bin/sqlplus / as sysdba <<EOF  
select status from v\$instance;
exit;
EOF
)

2 Answers2

5

Is your script indented like that? the delimiter for the here-doc has to be at the beginning of the line. This works for me:

#!/bin/bash
echo $(cat <<EOF
blah
EOF
)
ilkkachu
  • 133,243
  • 15
  • 236
  • 397
1

Ikkachu is correct that the code, when not indented, should work fine on any reasonably modern version of Bash. However, I would add that you may find it easier to understand and debug if you use a "here string" instead of a "here doc":

var=$(sqlplus / as sysdba <<< 'select status from v$instance; exit;')

Or, use a standard pipeline:

var=$(echo 'select status from v$instance; exit;' | sqlplus / as sysdba)
hackerb9
  • 1,418
  • 13
  • 20