如何摆脱给定路径中不必要的斜线?
例:
p="/foo//////bar///hello/////world"
我想要:
p="/foo/bar/hello/world"
phi*_*hag 24
使用readlink:
p=$(readlink -m "/foo//////bar///hello/////world")
请注意,这将规范化符号链接.如果那不是你想要的,请使用sed:
p=$(echo "/foo//////bar///hello/////world" | sed s#//*#/#g)
使用realpath:
realpath -sm $p
参数:
  -m, --canonicalize-missing   no components of the path need exist
  -s, --strip, --no-symlinks   don't expand symlinks
您的输入:
p="/foo//////bar///hello/////world"
命令删除不相关的斜杠:
echo $p | tr -s /
输出:
/foo/bar/hello/world
| 归档时间: | 
 | 
| 查看次数: | 10672 次 | 
| 最近记录: |