Score:0

How can I convert a Windows path to Unix?

cn flag

I want to create a program on Ubunut (WSL) that creates Folders and Text-documents. The user can type in a path, since Windows uses another path system we can’t just copy and paste. For convenience I want that the Windows path is automatically converted to a Unix path. Via the:

read -r path;

i ready the path in. How can I realize this, I tried multiple times. I also searched for answers in the internet but it never worked. The converted path is the destination:

cd $path

this should be also possible.

I hope for helpful answers, because i am already desperate .

Terrance avatar
id flag
Possible: https://superuser.com/questions/1113385/convert-windows-path-for-windows-ubuntu-bash
alonewolf avatar
cn flag
I know the version with wsl path but, for my program to work I need to save the path in a variable, how can I do that ?
Score:0
id flag

This should be able to accomplish what you are after by storing the Windows path as a Unix/Linux path variable in WSL:

Using the full path to the command of wslpath as a sub-command allows us to read in the "path" as a variable. If you are not sure what the full path is simply use which wslpath.

The commands below are in sequence of read in the path. Then convert the path variable to a Unix path. Then change to the $path folder.

read -r path;
path=$(/usr/bin/wslpath -a "$path")
cd "$path"

Example:

terrance@Terrance-Win10:~$ read -r path;
C:\\Program Files (x86)\\
terrance@Terrance-Win10:~$ path=$(/usr/bin/wslpath -a "$path")
terrance@Terrance-Win10:~$ cd "$path"
terrance@Terrance-Win10:/mnt/c/Program Files (x86)$
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.