Rod*_*uis 40
我不知道msys,但快速谷歌搜索向我显示它包括该sed实用程序.因此,假设它的工作方式与在msys本机Linux上的工作方式类似,这里有一种方法:
你必须用斜杠替换所有反斜杠,删除驱动器号后面的第一个冒号,并在开头添加斜杠:
echo "/$pth" | sed 's/\\/\//g' | sed 's/://'
Run Code Online (Sandbox Code Playgroud)
或者,如xaizek所述,
echo "/$pth" | sed -e 's/\\/\//g' -e 's/://'
Run Code Online (Sandbox Code Playgroud)
你必须添加一个分号,删除第一个斜杠并用反斜杠替换所有斜杠:
echo "$pth" | sed 's/^\///' | sed 's/\//\\/g' | sed 's/^./\0:/'
Run Code Online (Sandbox Code Playgroud)
或更有效率,
echo "$pth" | sed -e 's/^\///' -e 's/\//\\/g' -e 's/^./\0:/'
Run Code Online (Sandbox Code Playgroud)
where分别$pth是存储Windows或POSIX路径的变量.
ani*_*ane 26
你在cygwin上使用它吗?如果是的话,那么cygpath.exe在cygwin包中有一个现成的实用工具,只是为了做到这一点.
Output type options: -d, --dos print DOS (short) form of NAMEs (C:\PROGRA~1\) -m, --mixed like --windows, but with regular slashes (C:/WINNT) -M, --mode report on mode of file (binmode or textmode) -u, --unix (default) print Unix form of NAMEs (/cygdrive/c/winnt) -w, --windows print Windows form of NAMEs (C:\WINNT) -t, --type TYPE print TYPE form: 'dos', 'mixed', 'unix', or 'windows'
只需使用cygpath:
$ cygpath -w "/c/foo/bar"
-> C:\foo\bar
$ cygpath -u "C:\foo\bar"
-> /c/foo/bar
Run Code Online (Sandbox Code Playgroud)
你可能想知道:“我cygpath安装了吗?” 好,
cygpath可以在git-bash-install-folder\usr\bin\cygpath.exe.MSYS 中的“正确”方式是:
$ MSYS_NO_PATHCONV=1 taskkill /F /T /IM ssh-agent.exe
Run Code Online (Sandbox Code Playgroud)
这避免了必须手动翻译斜杠。它只是取消激活路径转换。