2

This is really strange. cgypath is returning paths with spaces in them, and when I try to cd to them, they fail as not being able to be found. I also notice this strange behavior with pwd. Observe this:

MyUser@MyMachine /cygdrive/c/Program Files/Java/jdk1.6.0_45
$ pwd
/cygdrive/c/Program Files/Java/jdk1.6.0_45

MyUser@MyMachine /cygdrive/c/Program Files/Java/jdk1.6.0_45
$ cd /cygdrive/c/Program Files/Java/jdk1.6.0_45
-bash: cd: /cygdrive/c/Program: No such file or directory

MyUser@MyMachine /cygdrive/c/Program Files/Java/jdk1.6.0_45

Why is this happening?

8

You need to escape your spaces with backslashes or quote your paths:

cd /cygdrive/c/Program\ Files/Java/jdk1.6.0_45

or

cd "/cygdrive/c/Program Files/Java/jdk1.6.0_45"

This is because commands take multiple arguments. The arguments are separated by spaces, so the command line thinks you pass the argument /cygdrive/c/Program and the argument Files/Java/jdk1.6.0_45 to the command cd.

  • Sorry I didn't include an example usage of cygpath, but it does contain quotes. I'm curious though, should pwd print a path that is accessible without alteration? – Zombies Mar 31 '14 at 15:53
  • Well, that means your example in your question is wrong, because in your example you don't use quotes. I'm currently not on windows, so I can't check cygwin, but on Mac, this works fine: Kay@Kays-Mac-Pro:/Volumes/xbmc/System Volume Information/ > cd "`pwd`" Kay@Kays-Mac-Pro:/Volumes/xbmc/System Volume Information/ > cd "`pwd`"/../ Kay@Kays-Mac-Pro:/Volumes/xbmc/ – user23127 Mar 31 '14 at 15:59
  • 1
    Oh I get it now. The quotes need to be on the output and not on the input (to the cygpath command) only. Since the output has unescaped spaces. – Zombies Mar 31 '14 at 16:16
  • @Zombies This comment should be an answer, you just saved me hours of pain – smac89 Apr 26 '16 at 6:02

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.