一个方便从windows复制文件或者目录到wsl的一个shell脚本。

▲ 效果

源码如下

1
2
3
4
5
6
7
8
9
10
str=$1

tmp=${str//\\/\/}
row=${tmp//\ /\\ }

typeset -l partition=$(echo $row|cut -d ":" -f1)
uri=$(echo $row|cut -d ":" -f2)
uri_l="/mnt/"${partition}${uri}

echo $uri_l|xargs -i cp -r {} .

字符串要替换第一个匹配的目标,写法为${str/old/new},若要全部替换则为${str//old/new}

主要要记下xrags的用法,下面是man xrags的解释。

1
2
3
4
5
6
7
8
-I replace-str
Replace occurrences of replace-str in the initial-arguments with names read from standard input. Also,
unquoted blanks do not terminate input items; instead the separator is the newline character. Implies
-x and -L 1.

-i[replace-str], --replace[=replace-str]
This option is a synonym for -Ireplace-str if replace-str is specified. If the replace-str argument is
missing, the effect is the same as -I{}. This option is deprecated; use -I instead.

-Ii大体上的意思是将xrags导过来的数据用{}取代

另外cut-d选项指定分隔符,默认为制表符(TAB)。