开发者

pipe inside array

How can I execute a piped command inside an array?

E.g.:

$ 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[@]}"

This outputs:

"DROP TABLE user1.\"${ORACLE_EXPDP_JOB_NAME}\";
COMMIT;
" | /opt/oracle/product/10.2.0/client/bin/sqlplus -S user1/password@database1

If I do an eval, the开发者_运维知识库 command was correctly executed, was showed bellow:

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

Commit complete.

BUT, if inside the result has an asterisk "*" and, I´d like to store it in a variable, the eval command will interpret the asterisk, cluttering the entire result:

$ 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.

Did you see?? --> a.log DEBUG_AD.log REPORT.log sent are files that are interpreted by eval when it met an asterisk on the result. I hoped the result would be like the one shown above, without the interpretation of the asterisk.


Solved myself!

I need only to echo the variable with double quotes to scape the asterisk interpretation.

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

Commit complete.

Sorry!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜