Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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

Your Answer


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.