Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I've got a script that scp's a file from remote host back to local. Sometimes the file names contain spaces. scp does not like spaces in its file names. For some reason my attempts at handling the spaces have not resulted in the correct scp path.

Code:

PATH=/var/root/Documents/MyFile OG-v1.2.3.pkg
scp $PATH Me@10.1.10.33:/Users/Me/Desktop

Results in

Cannot find directory: var/root/Documents/MyFile
Cannot find directory: OG-v1.2.3.pkg

Enclosing PATH in quotes "$PATH" gives the same error.

Swapping the spaces for escaped spaces also is not working, although as far as I can tell it should:

ESC_PATH=${PATH/' '/'\ '}

although printing the escaped path shows that the edit worked:

echo $ESC_PATH
> /var/root/Documents/MyFile\ OG-v1.2.3.pkg
share|improve this question
add comment

1 Answer

up vote 7 down vote accepted

You should quote both the declaration and the usage

PATH="/var/root/Documents/MyFile OG-v1.2.3.pkg"
scp "$PATH" Me@10.1.10.33:/Users/Me/Desktop

If you do not quote the first, $PATH will contain just the first part. If you do not quote the second, scp will treat each space-separated part as an argument.

share|improve this answer
    
Perfect! Thank's a million @Matteo. Turns out there was also a prefixed space throwing a wrench into it as well. –  Miles Alden Dec 7 '12 at 23:04
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.