Windows PATH 到 bash 中的 posix 路径转换 [英] Windows PATH to posix path conversion in bash

查看:28
本文介绍了Windows PATH 到 bash 中的 posix 路径转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将 Windows 目录路径(例如 c:/libs/Qt-static)转换为正确的 POSIX 目录路径(/c/libs/Qt-static) 通过标准的 msys 功能?反之亦然?

How can I convert a Windows dir path (say c:/libs/Qt-static) to the correct POSIX dir path (/c/libs/Qt-static) by means of standard msys features? And vice versa?

推荐答案

我不知道 msys,但是谷歌快速搜索显示它包含 sed公用事业.因此,假设它在 msys 中的工作方式与在本机 Linux 上的工作方式相似,这里有一种方法:

I don't know msys, but a quick google search showed me that it includes the sed utility. So, assuming it works similar in msys than it does on native Linux, here's one way how to do it:

您必须用斜杠替换所有反斜杠,删除驱动器号后的第一个冒号,并在开头添加一个斜杠:

You'll have to replace all backslashes with slashes, remove the first colon after the drive letter, and add a slash at the beginning:

echo "/$pth" | sed 's/\///g' | sed 's/://'

或者,正如 xaizek 所指出的,

or, as noted by xaizek,

echo "/$pth" | sed -e 's/\///g' -e 's/://'

从 POSIX 到 Windows

您必须添加一个分号,删除第一个斜杠并将所有斜杠替换为反斜杠:

From POSIX to Windows

You'll have to add a semi-colon, remove the first slash and replace all slashes with backslashes:

echo "$pth" | sed 's/^///' | sed 's///\/g' | sed 's/^./:/'

或更有效,

echo "$pth" | sed -e 's/^///' -e 's///\/g' -e 's/^./:/'

其中 $pth 是分别存储 Windows 或 POSIX 路径的变量.

where $pth is a variable storing the Windows or POSIX path, respectively.

这篇关于Windows PATH 到 bash 中的 posix 路径转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆