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