From owner-freebsd-questions Tue Jul 25 14:45:20 2000 Delivered-To: freebsd-questions@freebsd.org Received: from athserv.otenet.gr (athserv.otenet.gr [195.170.0.1]) by hub.freebsd.org (Postfix) with ESMTP id BC66837B9EE for ; Tue, 25 Jul 2000 14:45:15 -0700 (PDT) (envelope-from keramida@ceid.upatras.gr) Received: from hades.hell.gr (patr530-b082.otenet.gr [195.167.121.210]) by athserv.otenet.gr (8.10.1/8.10.1) with ESMTP id e6PLgpV11729; Wed, 26 Jul 2000 00:42:52 +0300 (EET DST) Received: (from charon@localhost) by hades.hell.gr (8.10.2/8.10.2) id e6PLgI735591; Wed, 26 Jul 2000 00:42:18 +0300 (EEST) Date: Wed, 26 Jul 2000 00:42:18 +0300 From: Giorgos Keramidas To: Matt Pillsbury Cc: freebsd-questions@freebsd.org Subject: Re: There must be a better way.... Message-ID: <20000726004218.A34623@hades.hell.gr> References: <20000723192635.A94476@straylight.NONE> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.4i In-Reply-To: <20000723192635.A94476@straylight.NONE>; from pillsy@brown.edu on Sun, Jul 23, 2000 at 07:26:35PM -0400 X-PGP-Fingerprint: 3A 75 52 EB F1 58 56 0D - C5 B8 21 B6 1B 5E 4A C2 X-URL: http://students.ceid.upatras.gr/~keramida/index.html Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On Sun, Jul 23, 2000 at 07:26:35PM -0400, Matt Pillsbury wrote: > I'm running bash, and I recently wanted to change a bunch of filenames > in a directory based on a glob: changing *.JPG to *.jpg . I knew that > > mv *.JPG *.jpg > > wouldn't cut it, but the solution I ultimately used seems really > cumbersome: > > for NAME in *.JPG; do mv $NAME `echo $NAME | sed -e 's/JPG/jpg/'`; done > > There's a more elegant solution, right? This is quite elegant for my taste. Ok, apart from the missing $ in the sed patterns, which I'd write as: sed -e 's/JPG$/jpg/' You can also use basename(1) for something like this: for fname in *.JPG ;do mv ${fname} "`basename ${fname} jpg`" ;done But this only proves that there are many many ways of doing the same thing, when you're on a Unix command line. If what you used worked for you, then why bother to prove it inelegant ? -- "The sun is the same in a relative way, but you're older. Shorter of breath, and one day closer to death." > Pink Floyd, TIME (Dark Side of the Moon) To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message