"

Getting "syntax error at line 19: `<<' unmatched" trying to run sqlplus in a ksh script.
...snip...

26 sqlplus $conn_str 1>/dev/null <<EOF
27 select sysdate from dual;
28 EOF

...snip...


The final sqlplus program can look like this;

...snip...

26 sqlplus $conn_str 1>/dev/null <<-EOF
27 select sysdate from dual;
28 EOF

...snip...


Describing the above program with the (space)/(no-space)/(no-characters) characters to make it more clear to understand the code; (space) means either a whitespace / a tab.

sqlplus $conn_str 1>/dev/null <<-EOF(no-space)(no-characters)
(space)select sysdate from dual;(space)
(no-space)(no-characters)EOF(no-space)(no-characters)
-------------------------------------------

In addition, here is some sample programs for you to test; Hope with this you may undestand the usage of "heredocument". It's better always use a '-' after << and before the first CONTENT tag

Program 1

RESULT="`sqlplus $USER/$PWD@$TNS <<-CONTENT
select sysdate from dual;
exit;
CONTENT
`";
echo "$RESULT"

Never add any other characters to the second tag (Eg:- Never do this [ CONTENT`";]. You will get error.

Describing the above program with the (space)/(no-space) characters;

RESULT="`sqlplus $USER/$PWD@$TNS(space)<<-CONTENT(no-space)
(space)select sysdate from dual;(space)
(space)exit;(space)
(no-characters)(no-space)CONTENT(no-space)(no-characters)
(space)`";(space)
echo "$RESULT"

-----------------------------------------------------------

Program 2

cat <<-CONTENT
echo "Hello Foo"
echo "Hello"; Hello "Foo";
CONTENT
CONTENT"
CONTENT

Describing the same program with the (space)/(no-space) characters;

cat(space)<<-CONTENT(no-space)
(no-space)echo "Hello Foo"(no-space)
(no-space)echo "Hello"; Hello "Foo";(no-space)
(space)(space)CONTENT(no-space)
(no-space)CONTENT"(no-space)
(no-space)CONTENT(no-space)

Only the Final CONTENT will match with the First CONTENT tag. Others have either a whitespace / a character attached to it and the KSH will not be able to recognise it, because it considers the whole as a string which doesn't match with the string CONTENT.

Output of the above program
echo "Hello"; Hello "Foo";
CONTENT
CONTENT"


To Conclude the CONTENT tag should not be attached with any characters including white space. Always use the '-' afterthe << and before the first CONTENT tag
Eg:-

cat <<-CONTENT
resolved
CONTENT

Description

cat(space)<<-CONTENT(no-space)(no-characters)
(space)(space)(space)(space)resolved(space)(space)(space)(any-characters)
(no-characters)(no-space)CONTENT(no-space)(no-characters)

Result follows;

resolved

posted @ 2012-03-13 10:16  MagicLetters  阅读(210)  评论(0编辑  收藏  举报