截断字符串的方法解析
1. dirnamebasename
$ basename /usr/local/share/doc/foo/foo.txt
foo.txt
$ basename /usr/home/drobbins
drobbins
===$ dirname /usr/local/share/doc/foo/foo.txt
/usr/local/share/doc/foo
$ dirname /usr/home/drobbins/
/usr/home
2.
///#从左向右,##最深的搜索,#最浅的搜索
$MYVAR=foodforthought.jpg
$ echo$
rthought.jpg
$ echo$
odforthought.jpg
=====
///%从右向左,%%最深的搜索,%最浅的搜索
$MYFOO="chickensoup.tar.gz"
$ echo$
chickensoup
$ echo$
chickensoup.tar
3.可以根据特定字符偏移和长度,使用另一种形式的变量扩展,来选择特定子字符串。试着在 bash 中输入以下行:
$ EXCLAIM=cowabunga
$ echo $
cow
$ echo $
abunga