Aug 182006
 

${parameter%word}
Remove smallest suffix pattern. The WORD is expanded to produce
a pattern. It then expands to the value of PARAMETER, with the
smallest portion of the suffix matched by the pattern deleted.

x=file.c
echo ${x%.c}.o
–>file.o

${parameter%%word}

Remove largest suffix pattern. The WORD is expanded to produce
a pattern. It then expands to the value of PARAMETER, with the
largest portion of the suffix matched by the pattern deleted.

x=posix/src/std
echo ${x%%/*}
–>posix

${parameter#word}
Remove smallest prefix pattern. The WORD is expanded to produce
a pattern. It then expands to the value of PARAMETER, with the
smallest portion of the prefix matched by the pattern deleted.

x=$HOME/src/cmd
echo ${x#$HOME}
–>/src/cmd

${parameter##word}
Remove largest prefix pattern. The WORD is expanded to produce
a pattern. It then expands to the value of PARAMETER, with the
largest portion of the prefix matched by the pattern deleted.

x=/one/two/three
echo ${x##*/}
–>three

Given
a=/a/b/c/d
b=b.xxx

csh bash result
— —- ——
$a:h ${a%/*} /a/b/c
$a:t ${a##*/} d
$b:r ${b%.*} b
$b:e ${b##*.} xxx

(source comp.unix.shell — http://groups.google.com/group/comp.unix.questions/browse_frm/thread/9127ba46689a0c13/2384610dc72c6ba8?lnk=gst&q=variable+expansions&rnum=2#2384610dc72c6ba8)

 Posted by at 3:06 pm