이 줄을 원격 파일로 어떻게 출력합니까?

이 줄을 원격 파일로 어떻게 출력합니까?

나는 bash 쉘을 사용하고 있으며 다음을 작성하는 올바른 방법을 찾으려고 노력하고 있습니다.

ssh mysuer@remotehost 'echo "update user set url = \'localhost\' where url = \'mydomain.com\';" >> /tmp/db.sql'

지금까지 위의 작업이 작동하지 않습니다.

Enter 키를 누른 후 다음 줄은 >어딘가에서 열린 인용문을 닫을 것으로 예상하는 것처럼 보입니다. 이렇게 하려면 어떻게 해야 합니까?

update user set url = 'localhost' where url = 'mydomain.com';

원격 파일로 출력됩니까?

답변1

작은따옴표는 이스케이프할 수 없지만 기존 인용문을 끝내고 아포스트로피( \')를 인쇄한 후 새 인용문을 열 수 있습니다.

올바른 구문은 다음과 같습니다.

ssh user@host 'echo "update user set url = '\''localhost'\'' where url = '\''mydomain.com'\'';" >> /tmp/db.sql'

답변2

mysql 문 내부의 작은따옴표에서 백슬래시를 제거하면 작동합니다.

ssh mysuer@remotehost 'echo "update user set url = 'localhost' where url = 'mydomain.com';" >> /tmp/db.sql'

관련 정보