WSL — Convert Windows Path to Linux Path in Shell

Photo by Gabriel Heinzer on Unsplash

Why we do this ?

Because the volume parameter of docker-compose only accepts WSL format

How do this ?

The test command realized by the sed command is as follows.

$ echo "c:/Project/test" \
| sed -E 's/^(\w+)+/\L\1/g' \
| sed -e 's/\\/\//g' \
| sed -e 's/://g' \
| sed -e '/^\//!s/^/\//g'
/c/Temp/test

Explanation:

  • sed -E ‘s/^(\w+)+/\L\1/g’ → Lowercase initial letters
  • sed -e ‘s/\\/\//g’ → Convert [] to [/]
  • sed -e ‘s/://’ → Remove [:]
  • sed -e ‘/^\//!s/^/\//g’ → If it does not start with [/], add [/] at the beginning

How use this ?

If we run this the output should be like below:

$ sh wsl.sh
/c/Temp/test

 by the author.

--

--

--

DevOps Consultant. I’m strongly focused on automation, security, and reliability.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Fastly, Google and Amazon’s “Bug Already Present” Pattern Caused 3 Biggest Outages This Year

pieces of a broken plate spread on the floor

Love your logs like Ice Cream!

Skychain March 2021 project development update

HoReCa App Principles

Making a RTS game #30: Refactoring our save/load system with binary serialisation 1/2 (Unity/C#)

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Maciej

Maciej

DevOps Consultant. I’m strongly focused on automation, security, and reliability.

More from Medium

How to install Ansible in RedHat Enterprise Linux 9 Beta — Ansible install

Linux: how to end to end verify UDP and TCP connectivity with nc

A curated list of “top” based monitoring tools for use in Linux and Unix terminals.

About Command Linux Shell