我的需要是让这个命令起作用:
sshpass -p XXXX ssh -oStrictHostKeyChecking=no [email protected] /cdn-cgi/l/email-protection sudo docker exec -u postgres postgres-container /bin/bash -c \" psql -d crawl-configuration -c 'select * from schema_version'\"
但结果表明 * 已被 shell 扩展,并且所有匹配的文件都作为参数传递给 psql 命令。于是我就搜索如何保护命令不被扩展,但没有成功。
我的实验给了我以下结果。
A - 以下命令有效,TOTO 显示在我的 shell 上
sshpass -p XXXX ssh -oStrictHostKeyChecking=no [email protected] /cdn-cgi/l/email-protection sudo docker exec -u postgres postgres-container /bin/bash -c \"echo TOTO\"
B - 以下命令不起作用,我的 shell 上显示一个空行
sshpass -p XXXX ssh -oStrictHostKeyChecking=no [email protected] /cdn-cgi/l/email-protection sudo docker exec -u postgres postgres-container /bin/bash -c "echo TOTO"
C - 这有效,显示 ls 的结果。我不明白为什么它有效但案例 B 不起作用?
sshpass -p XXXX ssh -oStrictHostKeyChecking=no [email protected] /cdn-cgi/l/email-protection sudo docker exec -u postgres postgres-container /bin/bash -c "ls"
D - 这有效,我得到了预期的结果
sshpass -p XXXX ssh -oStrictHostKeyChecking=no [email protected] /cdn-cgi/l/email-protection sudo docker exec -u postgres postgres-container /bin/bash -c \" psql -d crawl-configuration -c \'select version from schema_version\' \"
E - 在主机上执行此命令而不通过 ssh 有效
sudo docker exec -u postgres postgres-container /bin/bash -c " psql -d crawl-configuration -c 'select * from schema_version'"
使我的第一个命令起作用的解决方案是什么?