[英]How to convert a DOS-style path to Unix-style path under MSYS using simple commands?
For instance, if I have this as input: 例如,如果我将其作为输入:
F:\my\path\to\File.TXT
I want to get this as output 我想得到这个作为输出
/f/my/path/to/File.TXT
This should work even if the path doesn't exist, so I can't simply call 即使路径不存在,这也应该起作用,所以我不能简单地调用
cd $P && pwd -P
Edit: I'd like to avoid using sed and awk , since there are simpler commands to achieve this, like tr and Bash built-ins. 编辑:我想避免使用sed和awk ,因为有更简单的命令可以实现这一点,例如tr和Bash内置函数。
These 2 Bash functions will help: 这两个Bash函数将帮助:
canondirslashes() { local p; p="$(echo $1 | tr \\ /)" && echo ${p%/}; }
canonpath() { canondirslashes "$( test "${1:1:1}" != : && echo $1 || echo $(echo /${1::1} | tr [A-Z] [a-z])${1:2} )" ; }
Here's an example: 这是一个例子:
bash-3.1$ P=F:\\my\\path\\to\\File.TXT
bash-3.1$ echo $P
F:\my\path\to\File.TXT
bash-3.1$ canonpath $P
/f/my/path/to/File.TXT
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.