如何在 OS X 中显示已安装共享上的文件的完整网络路径

如何在 OS X 中显示已安装共享上的文件的完整网络路径

假设我有一个已安装的共享,例如:

/Volumes/temp

这可能映射到

cifs://servername/temp

使用 bash,如何获取共享上的文件的网络路径,例如

/Volumes/temp/folder/file.txt

答案1

如果我理解正确的话,你想替换路径的开头。你可以这样做:

file='/Volumes/temp/folder/file.txt'
echo ${file/#\/Volumes/cifs://servername}

描述如下man bash

   ${parameter/pattern/string}
          Pattern substitution.  The pattern is expanded to produce a pat‐
          tern just as in pathname expansion.  Parameter is  expanded  and
          the  longest match of pattern against its value is replaced with
          string.  If pattern begins with /, all matches  of  pattern  are
          replaced   with  string.   Normally  only  the  first  match  is
          replaced.  If pattern begins with #, it must match at the begin‐
          ning of the expanded value of parameter.  If pattern begins with
          %, it must match at the end of the expanded value of  parameter.
          [...]

相关内容