<i># Remove a trailing pathname component, leaving the head. This works like `dirname'.</i><br />
<br />
$ echo =ls(:h)<br />
<br />
/bin<br />
<br />
<br />
<i># Remove all leading pathname components, leaving the tail. This works like `basename'.</i><br />
<br />
$ echo =ls(:t)<br />
<br />
ls<br />
<br />
<br />
<i># Remove the suffix from each file (*.sh in this example)<br />
<br />
   $f:e is $f file extension<br />
<br />
   :h --> head (dirname)<br />
<br />
   :t --> tail (basename)<br />
<br />
   :r --> rest (extension removed) </i><br />
<br />
$ for f (*.sh) mv $f $f:r<br />
<br />
<br />
<i># Remove a filename extension of the form `.xxx', leaving the root name.</i><br />
<br />
$ echo $PWD<br />
<br />
/usr/src/linux<br />
<br />
$ echo $PWD:t<br />
<br />
linux<br />
<br />
<br />
<i># Remove all but the extension.</i><br />
<br />
$ foo=23.42<br />
<br />
$ echo $foo<br />
<br />
23.42<br />
<br />
$ echo $foo:e<br />
<br />
42<br />
<br />
<br />
<i># Print the new command but do not execute it. Only works with history expansion.</i><br />
<br />
$ echo =ls(:h)<br />
<br />
/bin<br />
<br />
$ !echo:p<br />
<br />
$ echo =ls(:h)<br />
<br />
<br />
<i># Quote the substituted words, escaping further substitutions.</i><br />
<br />
$ bar="23'42"<br />
<br />
$ echo $bar<br />
<br />
23'42<br />
<br />
$ echo $bar:q<br />
<br />
23\'42<br />
<br />
<br />
<i># Convert the words to all lowercase.</i><br />
<br />
$ bar=FOOBAR<br />
<br />
$ echo $bar<br />
<br />
FOOBAR<br />
<br />
$ echo $bar:l<br />
<br />
foobar<br />
<br />
<br />
<i># Convert the words to all uppercase.</i><br />
<br />
$ bar=foobar<br />
<br />
$ echo $bar<br />
<br />
foobar<br />
<br />
$ echo $bar:u<br />
<br />
FOOBAR<br />
<br />
<br />
<i># convert 1st char of a word to uppercase</i><br />
<br />
$ foo="one two three four"<br />
<br />
$ print -r -- "${(C)var}"<br />
<br />
One Two Three Four