在 Postgresql psql 中是否有 运行 bash 命令的快速方法,例如 Oracle SQL*Plus 中的感叹号?

Is there a quick way of running bash commands in Postgresql psql, like exclamation point in Oracle SQL*Plus?

在使用 Oracle SQL*Plus 时,可以使用 "!" 字符来执行 运行 shell 命令,例如

SQL>!pwd

查看当前工作目录。

我想知道在使用 psql 时是否有一些类似的快速方法可以对 Postgresql 执行相同的操作。

提前致谢,

是的,有办法做到这一点。您使用 \!<command>。示例:

\!ls

这是另一个例子:

bkregistration=# \!date
Sun Apr 22 11:13:47 BST 2018

命令行文档中是这样写的:

\! [COMMAND]   execute command in shell or start interactive shell