cygpath not able to convert Windows path to Linux path

北慕城南 提交于 2019-12-22 06:27:20

问题


Im trying to convert the file paths to/from Linux and Windows on Windows Machine.

unix path to windows works fine.

$ cygpath -w /cygdrive/c/CYGWIN/CYGBuild/build.mak
C:\CYGWIN\CYGBuild\build.mak

But windows path to Linux gives wrong output. i.e Missing '/' and also cygdrive

$ cygpath -u c:\cygwin\cygbuild\build.mak
c:cygwincygbuildbuild.mak

Anyone faced this issue?? Share your experience.

Thanks


回答1:


I got answer for this question.

$ cygpath -u 'c:\cygwin\cygbuild\build.mak'

i.e path should be given in single quotation.




回答2:


Actually as far as I know; you need forward slashes in paths used in cygwin. Single quotations help in cases where there are spaces (and my guess in this case; using backslashes instead of forward slashes) in the path. Otherwise backslashes are like escape characters, while spaces (although not in your case) require escape characters themselves. So quoting the path tends to eliminate such hassles.

Here are links that help me understand this:

  • This opencv (using cygwin) tutorial, page 4, where there's an example of paths used, with and without quotes, indicating when one might need them.
  • Also this is very useful; a list of Cygwin's FAQs, including how to deal with spaces (or in this case, backslashes in the path where adding quotes would help).



回答3:


cygpath's -m option is probably the easiest solution. Windows software generally accepts / as well as \. (There may be a few exceptions, but the development tools I work with have all been fine with it.)

$ cygpath -m /cygdrive/c/CYGWIN/CYGBuild/build.mak

C:/Cygwin/CYGBuild/build.mak



回答4:


No one seems to have explain why, we here is an explanation.

Cygpath will accept slashes, and back-slashes: c:/cygwin/cygbuild/build.mak c:\cygwin\cygbuild\build.mak. However the shell will interpret the back-slashes, therefore you need to stop the shell from interpreting the back-slashes.

You can stop the shell from interpreting back-slashes, in arguments, by preceding them with a back-slash, or by quoting (with single quotes): c:\\cygwin\\cygbuild\\build.mak or 'c:\cygwin\cygbuild\build.mak'.

Double quotes will not help in this case. Double quotes stops argument breaking on space, but does not stop interpretation of escapes (\), or dollar ($) expansion.



来源:https://stackoverflow.com/questions/12620306/cygpath-not-able-to-convert-windows-path-to-linux-path

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!