From owner-freebsd-questions Sat Sep 29 20:44:27 2001 Delivered-To: freebsd-questions@freebsd.org Received: from sylvester.dsj.net (sylvester.dsj.net [208.148.151.43]) by hub.freebsd.org (Postfix) with ESMTP id 8B08337B407 for ; Sat, 29 Sep 2001 20:44:23 -0700 (PDT) Received: (from dsj@localhost) by sylvester.dsj.net (8.9.3/8.9.3/Debian 8.9.3-21) id XAA29631; Sat, 29 Sep 2001 23:44:11 -0400 Date: Sat, 29 Sep 2001 23:44:11 -0400 From: "David S. Jackson" To: jacks@sage-american.com Cc: freebsd-questions@freebsd.org Subject: Re: Scripting question Message-ID: <20010929234411.B25861@sylvester.dsj.net> Reply-To: "David S. Jackson" References: <3.0.5.32.20010929222903.03f12c60@mail.sage-american.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <3.0.5.32.20010929222903.03f12c60@mail.sage-american.com>; from jacks@sage-american.com on Sat, Sep 29, 2001 at 10:29:03PM -0500 Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Sat, Sep 29, 2001 at 10:29:03PM -0500 jacks@sage-american.com wrote: > I'm putting the finishing touches on a automated cron script & some of its > scripting makes calls on other scripts that contain file names that need to > be changed each month, but cannot necessarily use the "date" command to > create the variable needed. > > What I need sounds pretty simple. I need to change a sub-script's string > without having to manually open the script file. e.g. change content string > "myfile.old" to "myfile.new"... for example: > #subscript > cp /usr/local/bin/myfile.old /somewhere/else > to read > cp /usr/local/bin/myfile.new /somewhere/else > > Thus, when the cron script calls this sub-script file (containing > "myfile.xxx)", it will have the new file reference name "myfile.new" when > it is supposed to be there. I hope I'm reading you right, but try this and see if it does what you want: for i in foo bar baz; do cp ${sourcedir}/${i}.old ${newdir}/${i}.new done You should wind up moving sourcdir/foo.old, sourcedir/bar.old, and sourcedir/baz.old to newdir/foo.new newdir/bar.new newdir/baz.new. You could also use for i in foo.old bar.old baz.old; do cp ${sourcedir}/${i} ${newdir}/${i%.*}.new done if you want to remove the existing suffix and replace it with a new one. All of above assumes we're talking about bash now. Hope this helps. -- David S. Jackson dsj@dsj.net =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= I base my fashion taste on what doesn't itch. -- Gilda Radner To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message