0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ShellでWindows PathをLinux Pathに変換(WSL)

0
Posted at

なぜやる

docker-composeのvolumeパラメータは、WSLの形式しか受け付けないから

どうやる

sedコマンドで実現する、テスト用コマンドは下記のようです。

$ echo "c:/Project/test" \
 | sed -E 's/^(\w+)+/\L\1/g' \
 | sed -e 's/\\/\//g' \
 | sed -e 's/://g' \
 | sed -e '/^\//!s/^/\//g'
/c/Project/test
  • sed -E 's/^(\w+)+/\L\1/g'
    • 頭文字を小文字
  • sed -e 's/\\/\//g'
    • [] を [/] に変換
  • sed -e 's/://'
    • [:] を削除
  • sed -e '/^\//!s/^/\//g'
    • [/]から始まるではない場合、先頭に[/]を追加

どうつかう

func.sh
# !bin/bash
  
wsl() { echo "$(echo "$1" | sed -E 's/^(\w+)+/\L\1/g' | sed -e 's/\\/\//g' | sed -e 's/://' | sed -e '/^\//!s/^/\//g')"; }

# quotes are necessary:
r=$(wsl 'C:\Project\test');

echo "$r";
$ sh func.sh
/c/Project/test
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?