Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 15 Sep 2000 08:43:58 +0100
From:      Dominic Mitchell <hdm@mistral.co.uk>
To:        Gary Kline <kline@thought.org>
Cc:        Gregory Bond <gnb@itga.com.au>, Randall Hopper <aa8vb@nc.rr.com>, freebsd-stable@FreeBSD.ORG
Subject:   Re: "set -A" Bourne script - a nogo on FreeBSD
Message-ID:  <20000915084358.B77219@bizboz.mistral.co.uk>
In-Reply-To: <200009150325.e8F3Pns34741@thought.org>; from kline@thought.org on Thu, Sep 14, 2000 at 08:25:48PM -0700
References:  <200009150310.OAA26100@lightning.itga.com.au> <200009150325.e8F3Pns34741@thought.org>

next in thread | previous in thread | raw e-mail | index | archive | help
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 majordomo@FreeBSD.org
with "unsubscribe freebsd-stable" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20000915084358.B77219>