scp 원격 파일을 로컬 시스템으로

scp 원격 파일을 로컬 시스템으로

스크립트의 일부로 원격 사이트에서 파일을 복사하려고 합니다. 그런데 오류가 발생했습니다. 나에게는 모든 것이 괜찮아 보이지만 조금 이상하게 들립니다.

#aaa="/path/to/some file with spaces(and brackets).txt"
....
#scp [email protected]:"$aaa" /test/
bash: -c: line 0: syntax error near unexpected token `('
bash: -c: line 0: `scp -f /path/to/some file with spaces.txt'

upd: 대괄호에 문제가 있습니다...

답변1

각 공백과 대괄호를 이스케이프 처리해야 합니다.

#!/bin/bash

aaa='/path/to/some\ file\ with\ spaces\(and brackets\).txt'
scp [email protected]:"$aaa" /test/

그런데 더 친근한 대안은 $aaa큰따옴표 외에 작은따옴표로 묶는 것입니다.

#!/bin/bash

aaa='/path/to/some file with spaces(and brackets).txt'
scp [email protected]:"'$aaa'" /test/

답변2

아래는 나를 위해 일했습니다. 내 생각에는 공백이나 괄호 등을 피하면 괜찮을 것 같습니다.

#!/bin/bash

aaa="/tmp/untitled\ text\ 2.txt"

scp -r [email protected]:"$aaa" .

답변3

나는 리터럴 이름이 `"/tmp/공백(및 대괄호).txt인 일부 파일을 사용하여 원격 호스트에 파일을 만들었습니다.

처럼 이름을 큰따옴표+작은따옴표로 붙여주면 옮길 수 있었어요. 이것에 영감을 받아질문.

/tmp$ scp remotehost:"'/tmp/some file with spaces(and brackets).txt'" .
some file with spaces(and brackets).txt          100%    0     0.0KB/s   00:00

변수로

/tmp$ aaa="/tmp/some file with spaces(and brackets).txt"
/tmp$ scp puppet:"'$aaa'" .
some file with spaces(and brackets).txt               100%    0     0.0KB/s   00:00

관련 정보