编写shell脚本的问题

编写shell脚本的问题

我从shell脚本中得到目录名,例如:/usr/local/aa/bb/cc
现在要把这个目录名中的cc提取出来,不知道用什么命令?
echo  "/usr/local/aa/bb/cc" | cut -b 18-
上面可以土土的搞定,下面是用gawk的方法
echo  "/usr/local/aa/bb/cc" | gawk -F"/" '{print $6}'
用basename这个命令就可以得到了
[victor@localhost ~]$ a="/usr/local/aa/bb/cc"
[victor@localhost ~]$ echo ${a##*/}
cc
[victor@localhost ~]$
journalist
[quote:0029301de5="twf_cc"][victor@localhost ~]$ a="/usr/local/aa/bb/cc"
[victor@localhost ~]$ echo ${a##*/}
cc
[victor@localhost ~]$[/quote]
why not use this method :
[code:1]
$ a="/usr/local/aa/bb/cc"
$ basename $a
[/code:1]
[quote:b53d73efdd="VimChina"][quote:b53d73efdd="twf_cc"][victor@localhost ~]$ a="/usr/local/aa/bb/cc"
[victor@localhost ~]$ echo ${a##*/}
cc
[victor@localhost ~]$[/quote]
why not use this method :
[code:1]
$ a="/usr/local/aa/bb/cc"
$ basename $a
[/code:1][/quote]

因為是內建 bash 命令,快得多。
journalist
[quote:8890713e77="twf_cc"][quote:8890713e77="VimChina"][quote:8890713e77="twf_cc"][victor@localhost ~]$ a="/usr/local/aa/bb/cc"
[victor@localhost ~]$ echo ${a##*/}
cc
[victor@localhost ~]$[/quote]
why not use this method :
[code:1]
$ a="/usr/local/aa/bb/cc"
$ basename $a
[/code:1][/quote]

因為是內建 bash 命令,快得多。[/quote]
看看哪个更简洁,便于阅读和理解,所以我更喜欢用basename
basename is enough
比较直接
谢谢各位