scp가 "해당 파일이 없습니다"라고 말하는 이유는 무엇입니까?

scp가 "해당 파일이 없습니다"라고 말하는 이유는 무엇입니까?

scp내 컴퓨터에서 다른 컴퓨터로 파일을 복사하는 데 사용하는 bash 스크립트가 있습니다 . 오류와 함께 SSH 비밀번호를 입력한 후에도 스크립트가 계속 종료됩니다.

<filename>: No such file or directory

그런데 스크립트에서 파일을 확인해 보니 아무 문제가 없습니다. 나는 set -o verbose 처음에 그랬고 스크립트가 끝나면 다음과 같은 내용을 얻습니다.

scp /Volumes/FX4\ HDD/Users/matthewdavies/Downloads/NCIS.S11E01.HDTV.x264-LOL.mp4 [email protected]:"/media/3TB/TV\ Shows/NCIS"
[email protected]'s password:
/Volumes/FX4\ HDD/Users/matthewdavies/Downloads/NCIS.S11E01.HDTV.x264-LOL.mp4: No such file or directory

그래서 scp출력된 대로 명령을 실행해 보았는데 괜찮았습니다. 복사했습니다. 무슨 일이야???

답변1

나는 당신이 무엇을 하고 있는지 완전히 확신하지 못하지만, 당신의 예에 있는 명령을 시도하면 다음과 같은 결과를 얻습니다.

$ scp /home/saml/projects/Cooks.com\ -\ Recipe\ -\ Coconut\ Chicken.mht \
       root@remotey:"/root/some spaced out file.mht"
scp: ambiguous target

이는 대상 경로를 인용하고 공백을 이스케이프하는 백슬래시도 포함하기 때문입니다. 그러나 현재 셸에서 큰따옴표가 벗겨지면 단일 백슬래시도 벗겨져 대상 경로가 공백이 있는 문자열로 남게 됩니다. 공백이 올바르게 이스케이프되도록 하려면 다음 중 하나를 수행하여 추가로 중첩해야 합니다.

방법 #1 - 큰따옴표, 작은따옴표

$ scp /path/with\ spaces/file\ with\ spaces.txt \
       user@remotey:"'/home/user/some spaced out file.txt'"

방법 #2 - 작은따옴표, 큰따옴표

$ scp /path/with\ spaces/file\ with\ spaces.txt \
       user@remotey:'"/home/user/some spaced out file.txt"'

방법 #3 - 작은따옴표, 백슬래시

$ scp /path/with\ spaces/file\ with\ spaces.txt \
       user@remotey:'/home/user/some\ spaced\ out\ file.txt'

방법 #4 - 큰따옴표, 백슬래시

$ scp /path/with\ spaces/file\ with\ spaces.txt \
       user@remotey:"/home/user/some\ spaced\ out\ file.txt"

방법 #5 - 삼중 백슬래시

$ scp /path/with\ spaces/file\ with\ spaces.txt \
       user@remotey:/home/user/some\\\ spaced\\\ out\\\ file.txt

관련 정보