Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我是 bash 脚本的新手。我有一个这样的字符串:\\abc\def\ghi
\\abc\def\ghi
我想使用分隔符解析字符串,并且需要一行命令将其转换为/abc/def/ghi(将 Windows 路径转换为 unix 路径)。
/abc/def/ghi
尝试这样做:
$ x='\abc\def\ghi' $ echo ${x//\\//} /abc/def/ghi
见参数扩展
笔记
或使用 sed:
kent$ echo -E "\abc\def\ghi"|sed 's:\\:/:g' /abc/def/ghi
string=$( echo "$string" | tr '\' '/' )