On Thu, Sep 14, 2000 at 08:25:48PM -0700, Gary Kline wrote:
>       I have a csh or sh question--sorry for asking it this way;
>       but is there any rational way of turning a file  named
> 
>       foo.c to foo.o or simply foo   with or without calling 
>       non-builtin programs?  I think I remember a sh wizard 
>       showing me some bizarre sh command...but not sure it wasn't
>       a dream!

$ fn=foo.c ; mv $fn ${fn%.c}.o

(Ideally I wouldn't need that semicolon there, but it doesn't appear to
work that way).

Look for the string "%%" in sh(1).  Generally, it's a way of of
stripping the right hand side off of strings.  Likewise, you can use "#"
and "##" to strip off the left hand side of strings.  For example, a
minimal replacement for basename(1):

$ me=/usr/local/bin/myscript
$ echo ${me##*/}
myscript

Note that these mechanisms are derived from ksh, so are not available
under every /bin/sh in the world, only really *BSD and Linux.

-Dom


To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-stable" in the body of the message

Reply via email to