我在shell脚本中有动态控制文件,如下所示
`echo 'LOAD DATA' >> $CTL_DIR/tjx_sc_req_upld.ctl
echo 'APPEND' >> $CTL_DIR/tjx_sc_req_upld.ctl
echo 'INTO TABLE TJX_SCR_UPLOAD_HEADER' >> $CTL_DIR/tjx_sc_req_upld.ctl
echo 'WHEN FILE_RECORD_DESCRIPTOR = ' \'FHEAD\' >> $CTL_DIR/tjx_sc_req_upld.ctl
echo 'FIELDS TERMINATED BY ","' >> $CTL_DIR/tjx_sc_req_upld.ctl
echo 'TRAILING NULLCOLS' >> $CTL_DIR/tjx_sc_req_upld.ctl
echo '(' >> $CTL_DIR/tjx_sc_req_upld.ctl
echo 'FILE_RECORD_DESCRIPTOR position(1),' >> $CTL_DIR/tjx_sc_req_upld.ctl
echo 'LINE_NO FILLER,' >> $CTL_DIR/tjx_sc_req_upld.ctl
echo 'SCHEDULE_NO ,' >> $CTL_DIR/tjx_sc_req_upld.ctl
echo 'SCHEDULE_DATE_TIME date' \'YYYYMMDD\' ',' >> $CTL_DIR/tjx_sc_req_upld.ctl
echo 'UPLD_TIME_STAMP sysdate,' >> $CTL_DIR/tjx_sc_req_upld.ctl
echo 'SEQ_NO "' ${exec_seq} '",' >> $CTL_DIR/tjx_sc_req_upld.ctl
echo 'FILENAME CONSTANT ' \'$FILENAME\' ',' >> $CTL_DIR/tjx_sc_req_upld.ctl
echo 'STATUS CONSTANT "UPLOADED"' >> $CTL_DIR/tjx_sc_req_upld.ctl
echo ')' >> $CTL_DIR/tjx_sc_req_upld.ctl`
使用上面的代码,shell脚本也运行正常。但是当我在OPTIONALLY ENCLOSED BY '"'
旁边添加fields terminated by
时,如下所示
echo 'FIELDS TERMINATED BY "," OPTIONALLY ENCLOSED BY '"' ' >> $CTL_DIR/tjx_sc_req_upld.ctl
我收到语法错误
./tjx_sc_req_upld.ksh: line 109: syntax error at line 216: `(`' unexpected
当我删除可选的封闭时我不会收到错误。
答案 0 :(得分:1)
你最终得到了无与伦比的报价。您需要进行一些转义才能获得文字单引号:
echo 'FIELDS TERMINATED BY "," OPTIONALLY ENCLOSED BY '\''"'\'' ' >> $CTL_DIR/tjx_sc_req_upld.ctl
您可以切换引号,使其不那么难看:
echo "FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' " >> $CTL_DIR/tjx_sc_req_upld.ctl