rsync 명령의 출력을 알림 메시지로 전달(macOS)

rsync 명령의 출력을 알림 메시지로 전달(macOS)

이는 일반적인 UNIX 문제일 수 있으므로 macOS에만 국한되지 않습니다. rsync 명령의 출력을 알림 메시지로 출력하고 싶습니다. 하지만 변수를 올바르게 배치하는 데 성공하지 못했습니다. 내 코드가 다음과 같은 경우:

RSYNC1="$(rsync --itemize-changes -avz -e ssh \
/Users/user/ server:/home/backup/ --delete)" && \
osascript -e 'display notification "${RSYNC1}" with title "Backup"'

그런 다음 ${RSYNC1}은 이와 같이 따옴표를 이스케이프하면 문자 그대로 인쇄됩니다.

osascript -e 'display notification \"${RSYNC1}\" with title "Backup"'

그러면 다음 오류가 발생합니다.

> 21:22: syntax error: „given“, „in“, „of“, experssion, „with“,
> „without“, other parameter name, etc. expected, but unknown token
> found. (-2741)

무엇을 바꿔야 합니까?

답변1

변수 확장을 얻으려면 큰따옴표를 사용해야 합니다. 큰따옴표 안에 리터럴 큰따옴표를 인쇄하려면 이를 이스케이프해야 합니다.

osascript -e "display notification \"${RSYNC1}\" with title \"Backup\""

또는 큰따옴표 안에 작은따옴표를 사용하세요.

osascript -e "display notification '${RSYNC1}' with title 'Backup'"

관련 정보