Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Linux by (18.4k points)

How can I convert my Windows dir path 

(say c:/libs/Qt-static) 

To the correct POSIX dir path is:

(/c/libs/Qt-static) 

Using these standard msys features? And vice versa?

1 Answer

0 votes
by (36.8k points)

I don't know much about msys, but a quick google search showed me that it includes the sed utility. So I assume it works similarly in msys than it does on native Linux, here's one way how to do it:

From Windows to POSIX

You need to replace all backslashes with slashes, remove the first colon after the drive letter, and add a slash at the beginning:

echo "/$pth" | sed 's/\\/\//g' | sed 's/://'

or, as noted by xaizek,

echo "/$pth" | sed -e 's/\\/\//g' -e 's/://'

From POSIX to Windows

You will need to add the semi-colon, remove the first slash and replace all slashes with backslashes:

echo "$pth" | sed 's/^\///' | sed 's/\//\\/g' | sed 's/^./\0:/'

or more efficiently,

echo "$pth" | sed -e 's/^\///' -e 's/\//\\/g' -e 's/^./\0:/'

where the $pth is to variable storing the Windows or POSIX path, respectively.

To know about Linux join the Linux training

Related questions

0 votes
1 answer
0 votes
1 answer
asked Dec 6, 2020 in Linux by blackindya (18.4k points)
0 votes
1 answer
0 votes
1 answer
asked Dec 5, 2020 in Linux by blackindya (18.4k points)
0 votes
1 answer

Browse Categories

...