From: http://www.cnblogs.com/slash/archive/2010/11/26/1888693.html
Some examples:
chj@linux-xzlr:Desktop\> AAA="hello First-of All"
chj@linux-xzlr:Desktop\> echo ${AAA#*-}
of All
chj@linux-xzlr:Desktop\> AAA=111-222
chj@linux-xzlr:Desktop\> echo ${AAA%-*}
111
chj@linux-xzlr:Desktop\> echo ${AAA#*-}
222
chj@linux-xzlr:Desktop\>
记住瞬间,精彩永恒
==============================================================
1.
--------------------------------------------------------------
chj@linux-xzlr:trunk\> AA="a bc d ef"
chj@linux-xzlr:trunk\> BB="d"
chj@linux-xzlr:trunk\> echo ${AA%%$BB*}
a bc
chj@linux-xzlr:trunk\> echo ${AA$BB}
bash: ${AA$BB}: bad substitution
chj@linux-xzlr:trunk\> echo ${AA#*$BB}
ef
chj@linux-xzlr:trunk\>
==============================================================
2.
--------------------------------------------------------------
cjash@linux-sdik:dl\> AAA=abcdef
cjash@linux-sdik:dl\> echo ${AAA:2}
cdef
cjash@linux-sdik:dl\> echo ${AAA-2}
abcdef
cjash@linux-sdik:dl\> echo ${AAA:-2}
abcdef
cjash@linux-sdik:dl\> echo ${AAA#2}
abcdef
cjash@linux-sdik:dl\> echo ${AAA#*2}
abcdef
cjash@linux-sdik:dl\> echo ${AAA 2}
bash: ${AAA 2}: bad substitution
cjash@linux-sdik:dl\> echo ${AAA$2}
bash: ${AAA$2}: bad substitution
cjash@linux-sdik:dl\> echo ${AAA: -2}
ef
cjash@linux-sdik:dl\> echo ${AAA%2}
abcdef
cjash@linux-sdik:dl\> echo ${AAA#*2}
abcdef
cjash@linux-sdik:dl\> echo ${AAA::2}
ab
cjash@linux-sdik:dl\>