Date: Sat, 29 Sep 2001 23:44:11 -0400 From: "David S. Jackson" <dsj@sylvester.dsj.net> To: jacks@sage-american.com Cc: freebsd-questions@freebsd.org Subject: Re: Scripting question Message-ID: <20010929234411.B25861@sylvester.dsj.net> 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 References: <3.0.5.32.20010929222903.03f12c60@mail.sage-american.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Sat, Sep 29, 2001 at 10:29:03PM -0500 jacks@sage-american.com <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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010929234411.B25861>
