如何在放置在 bash 脚本中时抑制 .sql 脚本的输出

How to supress the output of .sql script when placed inside bash script

下面是我的简单 bash 脚本:

#!/bin/bash
cd /app/oracle/client11_2/
connect <<EOF
@/app/oracle/client11_2/testquery.sql
exit;
EOF

注意:testquery.sql 包含一些 "SELECT" 查询,我还使用假脱机来存储查询的内容。

但是,当我在终端上执行 bash 脚本时,它会产生很多不需要的输出,如下所示:

SQL*Plus: Release 11.2.0.3.0
Copyright (c) 1982, 2011, Oracle.  All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options

如何避免这种输出..!?我不希望在执行 bash 脚本时将其打印在输出屏幕上。

将此处的文档 (<<) 片段设为:

connect <<EOF >/dev/null
@/app/oracle/client11_2/testquery.sql
exit;
EOF

这会将此处文档的 STDOUT 发送到 /dev/null


您还可以在 运行 时进行输出重定向,将脚本的整个 STDOUT 发送到 /dev/null 例如:

./script.sh >/dev/null

再次将脚本的整个 STDOUT 发送到 /dev/null (YMMV)。

您可以使用 -s 标志抑制 SQL*Plus header 消息

sqlplus -s

就是说,您的代码片段显示了一个连接,但没有显示 sqlplus 调用本身。不确定它被隐藏在哪里。