3

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.

4

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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