截斷字符串的方法解析
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