2011-04-07 57 views
0

如何在陣列內執行管道命令?管內陣列

例如:

$ ORACLE_USER=user1 
$ ORACLE_PASS=password 
$ ORACLE_CONN=database1 
$ ORACLE_EXPDP_JOB_NAME=expdp-job-name 
$ ORACLE_SQLPLUS_BIN=/opt/oracle/product/10.2.0/client/bin/sqlplus 
$ ORACLE_SQLPLUS_PARAMS=(-S "${ORACLE_USER}"/"${ORACLE_PASS}"@"${ORACLE_CONN}") 
$ CMD=(echo -e \"DROP TABLE "${ORACLE_USER}".'\"${ORACLE_EXPDP_JOB_NAME}\"'\;\\nCOMMIT\;\\n\" \| ${ORACLE_SQLPLUS_BIN} "${ORACLE_SQLPLUS_PARAMS[@]}") 

$ "${CMD[@]}" 

此輸出:

"DROP TABLE user1.\"${ORACLE_EXPDP_JOB_NAME}\"; 
COMMIT; 
" | /opt/oracle/product/10.2.0/client/bin/sqlplus -S user1/[email protected] 

如果我做一個eval,命令被正確執行時,被波紋管示:

$ eval "${CMD[@]}" 
DROP TABLE user1."expdp-job-name" 
         * 
ERROR at line 1: 
ORA-00942: table or view does not exist 

Commit complete. 

但是,如果內結果有一個星號「*」,我想將它存儲在AV良莠不齊,EVAL命令將演繹星號,攪亂整個結果:

$ ls -l 
total 2,1M 
-rw-r--r-- 1 root root 0 2011-04-07 14:33 a.log 
-rw-r--r-- 1 root root 186K 2011-04-06 12:05 DEBUG_AD.log 
-rw-r--r-- 1 root root 1,7M 2011-04-06 10:38 REPORT.log 
-rw------- 1 root root 57K 2011-04-06 10:38 sent 

$ b=`eval "${CMD[@]}"` 
$ echo $b 
DROP TABLE user1."expdp-job-name" a.log DEBUG_AD.log REPORT.log sent ERROR at line 1: ORA-00942: table or view does not exist Commit complete. 

你有沒有看到? - >a.log DEBUG_AD.log REPORT.log發送的是eval在結果上遇到星號時解釋的文件。 我希望結果如上所示,沒有星號的解釋。

回答

1

解決了我自己!

我只需要用雙引號來回顯變量以檢查星號解釋。

echo "$b" 
DROP TABLE user1."expdp-job-name" 
        * 
ERROR at line 1: 
ORA-00942: table or view does not exist 

Commit complete. 

對不起!