bash 将反斜杠转换为批处理文件中的转发

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6189771/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 00:05:43  来源:igfitidea点击:

convert backslashes to forward in batch files

bashbatch-file

提问by remo

whats the easiest way of converting all backslashes to forward in a path in a batch file, since I need to use bash for execution.

将所有反斜杠转换为批处理文件中路径的最简单方法是什么,因为我需要使用 bash 来执行。

回答by Andriy M

SET "string=D:\path\to\folder"
ECHO %string:\=/%

Basically, you need first to store the string value into an environment variable, then use the following template:

基本上,您首先需要将字符串值存储到环境变量中,然后使用以下模板:

%variable:str1=str2%

to replace every occurrence of str1in variablewith str2.

更换的每次出现str1variablestr2

You can always remind yourself about this pattern by invoking SET /?from the command prompt.

您始终可以通过SET /?从命令提示符调用来提醒自己注意此模式。

回答by Blagovest Buyukliev

echo 'C:\Program Files\Program' | sed -e 's/\/\//g'