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

CONTROLLING LIGHT USING TELEGRAM AND SENDING VALUES TO ADAFRUIT

How to sync SQLite on Django with PostgreSQL on heroku

Kubernetes certification tips

Kubernetes: Breathing New Life into On-Premise Services

How we build a clone of ShopClues.com

We Scrum, but we also have Steering Committees

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

Enable services on boot on remote hosts — Ansible module service_facts , service

[project]The basics of Docker and K8s

Dockerfile COPY cannot find the file

Ingesting and processing multiple lines in Linux using an array and loops.