2015-12-11 37 views
0

我想在shell腳本中記錄獨立塊的行號。

我想使用下面的代碼,但它不工作。請讓我知道是否有一個工作解決方案。

#!/bin/ksh 

result=`sqlplus -s $DATABASE <<EOF 
SET SET HEAD OFF; 
SET PAGES 0; 
SET FEEDBACK OFF; 
SET SERVEROUTPUT ON SIZE UNLIMITED; 
SET DEFINE OFF; 

BEGIN 
    DBMS_OUTPUT.put_line ('Line number: '|| $$plsql_line); 
END; 
/
EOF` 
echo $result 

我收到以下錯誤:

PLS-00103: Encountered the symbol "PLSQL_LINE" when expecting one of the following: 
) = - + </> at in is mod remainder not rem => <an exponent (**)> <> 
or != or ~= >= <= <> and or like like2 like4 likec as between from using 
|| member submultiset The symbol "," was substituted for "PLSQL_LINE" to continue 

回答

1

$需要進行轉義:

DBMS_OUTPUT.put_line ('Line number: '|| \\$\\$plsql_line); 
1

的問題是,這裏的文檔(從第一個<<EOF)是擴展shell變量(任何以$開頭的東西)。您可以通過

  • 把一個反斜槓每個$前抑制行爲,
  • 或指出的是,這裏的文件有沒有有用的shell變量,可以援引第EOF,例如,

    結果=` sqlplus的-s $ DATABASE < < 「EOF」

result=`sqlplus -s $DATABASE <<'EOF' 

進一步閱讀: