gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:36:00 24 4
gpt4 key购买 nike

我正在远程 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com