Path conversion in git bash

taijidude - Feb 17 '23 - - Dev Community

Hello again,

today i have a small advice for you if you work with the git bash on windows.

To quickly convert paths from windows format to unix format you can use the cygpath tool:

Unix to windows:

$ cygpath -w /d/temp
D:\temp
Enter fullscreen mode Exit fullscreen mode

Windows to unix:

$ cygpath -u 'D:\temp'
/d/temp
Enter fullscreen mode Exit fullscreen mode

Another nice tool that helps you with the conversion of an relative path is realpath. This is useful because it allows your scripts to accept relative paths and than figure out the absolute paths themselve.

Example:

$ ls 
test.txt
$ realpath -s ./test.txt
/d/realpathtest/test.txt
Enter fullscreen mode Exit fullscreen mode

When you give an absolute path to realpath it will just print this path. So if you are working with file paths, this will make your scripts more flexible.

$ realpath -s /d/realpathtest/test.txt
/d/realpathtest/test.txt
Enter fullscreen mode Exit fullscreen mode


`

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player