Remove unnecessary slashes from a given path with bash

前端 未结 8 1907
囚心锁ツ
囚心锁ツ 2021-02-05 15:04

How can I get rid of unnecessary slashes in a given path?

Example:

p=\"/foo//////bar///hello/////world\"

I want:

p=\"/f         


        
8条回答
  •  走了就别回头了
    2021-02-05 15:14

    With realpath:

    realpath -sm $p

    Parameters:

      -m, --canonicalize-missing   no components of the path need exist
      -s, --strip, --no-symlinks   don't expand symlinks
    

提交回复
热议问题