getting syntax error at line 34 : `<<' unmatched in ksh script

匿名 (未验证) 提交于 2019-12-03 01:05:01

问题:

I have a shell script, when I execute it, I get the error

syntax error at line 34 : `<<' unmatched in ksh script  column_name=`sqlplus -s $BASE_DB_CONN<<!!     WHENEVER SQLERROR exit ROLLBACK     set SQLPROMPT ''     set heading off     set pagesize 1000     set linesize 5000     set feedback off     set define on     set verify off     @smm9_stream_map.sql $STREAM_NAME $FIELD_NAME"     exit     !!`; 

To my surprise the same thing works in the while loop altered script as below

while [ $a -lt ${NO_LOOP} ] do column_name=`sqlplus -s $BASE_DB_CONN<<!!     WHENEVER SQLERROR exit ROLLBACK     set SQLPROMPT ''     set heading off     set pagesize 1000     set linesize 5000     set feedback off     set define on     set verify off     @smm9_stream_map.sql $STREAM_NAME $FIELD_NAME"     exit     !!`; a=`expr $a + 1` done 

Why does the second script work but not the first one?

回答1:

The heredoc terminator must be the only text on that line, no other whitespace allowed (*)

column_name=$(sqlplus -s $BASE_DB_CONN<<!!     ....     exit !! ) 

(*) the exception being, for heredocs using <<-, any leading tabs will be stripped from the heredoc, including from the terminator. I see in my ksh93 man page:

If # is appended to <<, then leading spaces and tabs will be stripped off the first line of the document and up to an equivalent indentation will be stripped from the remaining lines and from word.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!