calling sqlplus from within a for loop

i'm not new to programming, but i AM new to unix scripting. here's my deal.

this works:

#!/bin/ksh
echo "HELLO"

/oracle_home/bin/sqlplus username/password@MYDB<<EOF
SELECT COUNT(*) FROM EMPLOYEES;
EOF
exit

echo "GOODBYE"

this doesn't:

#!/bin/ksh
echo "HELLO"

for x in 1 2 3 4 5 
do

/oracle_home/bin/sqlplus username/password@MYDB<<EOF
SELECT COUNT(*) FROM EMPLOYEES;
EOF
exit

done

echo "GOODBYE"

i get this error:

yyy[9]: syntax error at line 12 : `<<' unmatched

why???????

Make sure "EOF" does not have white space in front of it.

1 Like

i tested both scripts and they worked fine, I don't see a reason why this has something to do
with the loop, since it's absolutely the same, the loop just runs one time because of the exit, I don't see the sense of script nr2 :slight_smile:

shell/ksh can be picky about the end of a here document.
Make sure there is not white space before or after the "EOF"

the reason the script doesn't accomplish anything is because it's a stripped down version of the real script. i can't go posting sensitive information on here! :stuck_out_tongue:

i've f'd around with this for hours. finally i created a new file, typed the same thing, executed it, and it worked!!! :eek:

i'm about to lose my mind over here...