linux - bash 通过 ssh 连接列出 postgresql 数据库

标签 linux bash postgresql ssh

我正在远程 Postgresql 数据库上做一些工作。

当我登录到服务器时,此命令适用于 bash: $ psql -c "\l"

可以通过 ssh 远程登录:

ssh user@server -C "cd /tmp && su postgres -c psql"

但为什么这个命令不起作用?

ssh user@server -C " cd /tmp && su postgres -c psql -c '\l' "
→   bash: l: command not found

这是有效的,也是“psql -l”,但我不明白为什么我必须在这里使用反斜杠 3 次?

ssh user@server -C " cd /tmp && su postgres -c 'psql -c \\\l' "

最佳答案

使用多个级别的引用:

ssh user@server -C "cd /tmp && su postgres -c 'psql -c \"\\l\"'"

双反斜杠不是必需的,因为 \l 不是可识别的转义序列。

关于linux - bash 通过 ssh 连接列出 postgresql 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48990429/

相关文章:

ruby-on-rails - 我应该将连接表连接到另一个表吗?

C:在不使用全局变量的情况下,从创建的线程中操作在 main 中声明的结构

php - 无法打开流

json - 使用 jq 通过搜索子键/值对来选择父级

linux - 来自 TAR 输出的 Grep 模式

jquery - rails : How to get Jquery to update a database column after a click

postgresql - 为什么这个 postgres 函数只在一个特定的数据库上失败?

linux - 如何使用 iperf 从 bash 输出中获取选定的文本

linux - SVN:结帐访问被拒绝

linux - 从终端运行 emacs 作为单独的进程