在第34行获取语法错误:'<<'在ksh脚本中无法比拟 [英] getting syntax error at line 34 : `<<' unmatched in ksh script
问题描述
我有一个shell脚本,执行该脚本时会出现错误
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
!!`;
令我惊讶的是,相同的东西在while循环更改的脚本中起作用,如下所示
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?
推荐答案
heredoc终止符必须是该行上仅 的文本,不允许使用其他空格(*)
The heredoc terminator must be the only text on that line, no other whitespace allowed (*)
column_name=$(sqlplus -s $BASE_DB_CONN<<!!
....
exit
!!
)
(*)是一个例外,对于使用<<-
的heredocs,任何前导选项卡都将从Heredoc中删除,包括终止符.我在ksh93手册页中看到了
(*) 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:
如果将#附加到<< ;,则前导空格和制表符将为 删除文档的第一行,最多将缩进相同的缩进 从其余的行和 word 中删除.
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.
这篇关于在第34行获取语法错误:'<<'在ksh脚本中无法比拟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!