我的要求是从plsql过程调用shell脚本并将参数从plsql传递给shell脚本。 我现在面临的问题是,如果参数中包含任何空格,那么shell脚本会将其视为单独的参数值。
从pl sql到shell脚本的输入如下
abc@xyz.com##ace321##https://companyurl.com XRX_Test,AL
LDG,Test,Test,false,2,5 XRX_Test,AL LDG,Test1,Test1,false,2,5
此处 Arg1 为"abc@xyz.com##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:" "$@"
for l_temp in "$@"
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"
并从上面的shell脚本输出如下(虽然我只传递3个参数,因为空间我得到5个参数)
Process argument begins
The total arg: 5
Received arguments: abc@xyz.com##ace321##https://companyurl.com XRX_Test,AL LDG,Test,Test,false,2,5 XRX_Test1,AL LDG,Test1,Test1,false,2,5
arguments: + " abc@xyz.com##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 "abc@xyz.com##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: abc@kbace.com##ace321##https:companyurl.com XXX_Test,AL LDG,Test1,Test1,false,2,5 XXX_Test2,AL LDG,Test1,Test1,false,2,5
arguments: + " abc@xyz.com##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 "abc@xyz.com##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 :(得分:0)
将参数传递给脚本时,只需将它们放在引号之间:
bash script.sh "abc@xyz.com##ace321##https:companyurl.com" "XXX_Test,AL LDG,Test1,Test1,false,2,5" "XXX_Test2,AL LDG,Test1,Test1,false,2,5"