${#string} $string的長度
${string:position} 在$string中,從位置$position開始提取子串
${string:position:length} 在$string中,從位置$position開始提取長度為$length的子串
在shell中,通過awk,sed,expr 等都可以實作,字元串上述操作。下面我們進行性能比較。
[chengmo@localhost ~]$ test='c:/windows/boot.ini'
[chengmo@localhost ~]$ time for i in $(seq 10000);do a=${#test};done;
real 0m0.173s
user 0m0.139s
sys 0m0.004s
[chengmo@localhost ~]$ time for i in $(seq 10000);do a=$(expr length $test);done;
real 0m9.734s
user 0m1.628s
原文:
http://www.cnblogs.com/chengmo/archive/2010/10/02/1841355.html