I'm new to bash scripting. I have a string which is like so: \\abc\def\ghi
我是新的bash脚本编程。我有一个这样的字符串:\abc\def\ghi
I want to parse the string using a delimiter and need a one line command for converting it to /abc/def/ghi
(convert Windows path to unix path).
我想使用分隔符解析字符串,需要一个行命令将其转换为/abc/def/ghi(将Windows路径转换为unix路径)。
3 个解决方案
#1
3
Try doing this :
试着这样做:
$ x='\abc\def\ghi'
$ echo ${x//\\//}
/abc/def/ghi
看到参数扩展
NOTE
请注意
- parameter expansions are bash built-ins, so it's quicker than external commands
- 参数扩展是bash内置的,所以它比外部命令快
#2
0
string=$( echo "$string" | tr '\' '/' )
#3
0
or with sed:
或对话:
kent$ echo -E "\abc\def\ghi"|sed 's:\\:/:g'
/abc/def/ghi
#1
3
Try doing this :
试着这样做:
$ x='\abc\def\ghi'
$ echo ${x//\\//}
/abc/def/ghi
看到参数扩展
NOTE
请注意
- parameter expansions are bash built-ins, so it's quicker than external commands
- 参数扩展是bash内置的,所以它比外部命令快
#2
0
string=$( echo "$string" | tr '\' '/' )
#3
0
or with sed:
或对话:
kent$ echo -E "\abc\def\ghi"|sed 's:\\:/:g'
/abc/def/ghi