mkcmd.c (in net.sources) alternate approach
Spencer W. Thomas
thomas at utah-gr.UUCP
Wed Jul 11 02:53:47 AEST 1984
Actually, Don, your second example can be done much more easily in csh
than you show (it's funny how we stick with the idioms we originally
learned, even when they're not appropriate).
> # rename *.ftn *.ft4
>
> foreach i (*.ftn)
> ? mv $i `basename $i ftn`ft4
> ? end
The 'mv' line can be done more efficiently as
? mv $i $i:r.ft4
In fact, the csh provides a whole set of modifiers for collecting parts
of file names
$i:h "Head" - strips the last component off the path.
$i:t "Tail" - returns the last component of the path.
$i:r "Root" - strips the part after the last '.' off the filename
(or path)
$i:e "Extension" - just the part after the '.' (this may be new,
I don't remember it before).
Examples of use (suppose $i contains '/a/b/d.c')
echo $i:h -> /a/b
echo $i:t -> d.c
echo $i:r -> /a/b/d
echo $i:e -> c
=Spencer
More information about the Comp.unix
mailing list