0

I'm having trouble passing a path as an argument which has a space inside.

keyLocation="/Users/vladimir/Google\ Drive/file.pem"
ssh -i $keyLocation [email protected];

This give me the below error:

Warning: Identity file /Users/vladimir/Google not accessible: No such file or directory.

Basically after the assignment keyLocation itself becomes "/Users/vladimir/Google Drive/file.pem" (no ) so when it tries to use $keyLocation as an argument it passes it as

ssh -i /Users/vladimir/Google Drive/file.pem [email protected]

How can I make the ssh command recognise it as a path which has a space inside?

1
  • 1
    $"$keyLocation" Commented Dec 19, 2013 at 16:43

3 Answers 3

12

You mixed it up a little bit. Spaces don't need to be escaped inside quotes. And when you expand a variable containing space, always quote it.

keyLocation="/Users/vladimir/Google Drive/file.pem"
ssh -i "$keyLocation" [email protected]

See: Quotes and escaping [Bash Hackers Wiki]

0

Frank answered it in the comments:

$"$keyLocation"

Thanks, Frank.

1
0

For me storing the path into a variable did not do the trick.

A different approach is to use a symbolic link

ln -s ~/Google\ Drive/ Drive

After that you can use

ssh -i ~/Drive/file.pem [email protected]

Hope that helps someone else!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .