2015-05-07 116 views
0

我的要求是從plsql過程調用shell腳本並將參數從plsql傳遞到shell腳本。 我現在面臨的問題是,如果參數之間包含任何空格,則shell腳本會將其視爲單獨的參數值。shell腳本的空格分隔參數

從PL SQL到shell腳本中輸入如下

[email protected]##ace321##https://companyurl.com XRX_Test,AL 
LDG,Test,Test,false,2,5 XRX_Test,AL LDG,Test1,Test1,false,2,5 

這裏ARG1"[email protected]##ace321##https:companyurl.com"Arg2所得"XXX_Test,AL LDG,Test1,Test1,false,2,5"ARG3"XXX_Test2,AL LDG,Test1,Test1,false,2,5"

在shell腳本我想如下

echo "Process argument begins" 
    echo "The total arg:" "$#" 
    echo " Received arguments:" "[email protected]" 
    for l_temp in "[email protected]" 
     do 
      echo "arguments:" + ' "' "$l_temp" '"' 
      # EXTRACT_NAME+=' "' "$l_temp" '"' 
      EXTRACT_NAME+=' "' 
      EXTRACT_NAME+="$l_temp" 
      EXTRACT_NAME+='"' 
     done 
    echo "Complete List" "$EXTRACT_NAME" 
    echo "Process argument ends" 
從上述外殼腳本輸出

和如下(雖然我只通過3個參數,由於空間我得到5個參數)需要

Process argument begins 
The total arg: 5 
Received arguments: [email protected]##ace321##https://companyurl.com XRX_Test,AL LDG,Test,Test,false,2,5 XRX_Test1,AL LDG,Test1,Test1,false,2,5 
arguments: + " [email protected]##ace321##https://companyurl.com " 
arguments: + " XRX_Test,AL " 
arguments: + " LDG,Test,Test,false,2,5 " 
arguments: + " XRX_Test1,AL " 
arguments: + " LDG,Test1,Test1,false,2,5 " 
Complete List "[email protected]##ace321##https://companyurl.com" "XRX_Test,AL" "LDG,Test,Test,false,2,5" "XRX_Test1,AL" "LDG,Test1,Test1,false,2,5" 
Process argument ends 

但實際O/P是如下

Process argument begins 
The total arg: 3 
Received arguments: [email protected]##ace321##https:companyurl.com XXX_Test,AL LDG,Test1,Test1,false,2,5 XXX_Test2,AL LDG,Test1,Test1,false,2,5 
arguments: + " [email protected]##ace321##https:companyurl.com " 
arguments: + " XXX_Test,AL LDG,Test1,Test1,false,2,5 " 
arguments: + " XXX_Test2,AL LDG,Test1,Test1,false,2,5 " 
Complete List "[email protected]##ace321##https:companyurl.com" "XXX_Test,AL LDG,Test1,Test1,false,2,5" "XXX_Test2,AL LDG,Test1,Test1,false,2,5" 
Process argument ends 

有人可以幫助我嗎?我需要在shell腳本中做些什麼改變才能避免空間或特殊字符? 感謝

回答

0

當傳遞參數給你的腳本,只是把它們引號之間:

bash script.sh "[email protected]##ace321##https:companyurl.com" "XXX_Test,AL LDG,Test1,Test1,false,2,5" "XXX_Test2,AL LDG,Test1,Test1,false,2,5" 
+0

是的,我已經嘗試了這種做法。我在pl sql中添加引號給我的參數併發送,但是當我在shell腳本中接收時,它不帶引號出現,因此出現問題。正如我上面提到的,當我回聲$ @它打印沒有引號的參數並導致問題。 – user2967784

+0

我已經嘗試從shell啓動腳本,它發現3個參數,也許引號需要逃脫? –

+0

是的,當我從命令提示符運行shell並使用雙引號傳遞參數時,它工作正常。這就是我在將它傳遞給shell腳本之前追加引號的原因。但是有一些我在shell腳本中無法得到引號的時候 – user2967784