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 needed to write a that behaves correctly with nasty (spaces, braces, etc..) filenames.

scp -rv "$1" shiny:/Volumes/Seagate3To/\"$1\"

This function works, but I don't understand why the quotes need escaping in the second argument of scp.

share|improve this question
add comment

1 Answer 1

up vote 4 down vote accepted

Let say $1 is

This is a test directory name

We escape the double quote because we want to pass the target directory (part after colon) as a whole (including the double quotes) to the target machine.

Following is what we want to past to target

/Volumes/Seagate3To/"This is a test directory name"

Without the escape, the double quote will be consumed by the local machine and following string is sent, which become 6 strings separated by space

/Volumes/Seagate3To/This is a test directory name

Resulting an error.

share|improve this answer
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.