Cygwin convert windows path to unix then change dir

4

2

I am usually trying to use the cygwin terminal to move to a nested directory. The problem is the windows directory are not immediately interpreted.

So I had to do two step:

$ cygpath -u "C:\Develop\blah\blah\blah\too_deep\"
/cygdrive/c/Develop/blah/blah/blah/too_deep/
$ cd /cygdrive/c/Develop/blah/blah/blah/too_deep/

I need to convert the path first then paste the result to change it.

I tried to use redirect but it does not work. Any ideas?

$ cygpath -u "C:\Develop\blah\blah\blah\too_deep\" | cd

=> No results.

Nassign

Posted 2015-03-05T01:43:22.700

Reputation: 353

Possible duplicate of Use output from command line as a parameter for a command

– Scott – 2019-02-10T20:46:11.840

Answers

7

Try this:

cd $(cygpath -u 'C:\Develop\blah\blah\blah\too_deep\')

The $(command) construct does a command substitution and is replaced with the output of the command.

erichui

Posted 2015-03-05T01:43:22.700

Reputation: 844

8

You'll need to enclose it in double quotes if the path contains spaces:

cd "$(cygpath -u 'c:\Program Files\')"

Planetoid Hsu

Posted 2015-03-05T01:43:22.700

Reputation: 81

You repeat the old answer! – Romeo Ninov – 2016-04-21T07:08:53.347

4actually, not quite. He's enclosed that with double quotes. Not sure if it'll work, but it does seem marginally unique – Journeyman Geek – 2016-04-21T07:48:08.840

Confirmed as working. However so does the version without double quotes as per the accepted answer. – DavidPostill – 2016-04-21T09:55:04.367

5When I test previous version:

$ cd $(cygpath -u 'c:\Program Files\')

I met the error message: -bash: cd: /cygdrive/c/Program: No such file or directory. – Planetoid Hsu – 2016-04-21T11:16:44.983

0

or simple old fashioned

cd `cygpath --unix "C:\Develop\blah\blah\blah\too_deep\ "`

Please note the space after the last backslash.

Ch.K.

Posted 2015-03-05T01:43:22.700

Reputation: 1