pax*_*blo 14
在bash,它删除前缀模式.
在这里,它基本上为您提供了最后一个/路径分隔符后的所有内容(通过删除前缀*/,后跟任意数量的字符/):
pax> fspec=/path/to/some/file.txt
pax> echo ${fspec##*/} # greedy remove */ at start
file.txt
Run Code Online (Sandbox Code Playgroud)
还有一个单#变量,它是一个非贪婪的匹配和后缀的等价物:
pax> echo ${fspec#*/} # non-greedy remove */ at start
path/to/some/file.txt
pax> echo ${fspec%%/*} # greedy remove /* at end
pax> echo ${fspec%/*} # non-greedy remove /* at end
/path/to/some
Run Code Online (Sandbox Code Playgroud)
这些##*/和%/*大致相当于你从中获得的内容basename和内容dirname,但在bash此之内你不必调用外部程序:
pax> basename $fspec
file.txt
pax> dirname $fspec
/path/to/some
Run Code Online (Sandbox Code Playgroud)