Date: Sun, 30 Sep 2001 16:08:26 -0500 From: Mike Meyer <mwm@mired.org> To: jacks@sage-american.com Cc: questions@freebsd.org Subject: Re: Scripting question Message-ID: <15287.35274.798595.307311@guru.mired.org> In-Reply-To: <72642935@toto.iv>
next in thread | previous in thread | raw e-mail | index | archive | help
jacks@sage-american.com types: > 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. Want to describe how they need to be changed? You can do quite a bit with the date command and a little script magic. > 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. Well, passing the file name in as an argument is one easy way to do it. If you can't change the argument handling of the subscript for some reason, you can use an environment variable, like so: #script TARGETFILE=myfile.new subscript #subscript ${TARGETFILE:=myfile.old} cp /usr/local/bin/$TARGETFILE /somewhere/else In the extreme case, you cram one or more commands into a variable and eval the variable: #script VARIABLECOMMAND='cp /usr/local/bin/myfile.new /seomwhere/else' subscript #subscript eval ${VARIABLECOMMAND:-'cp /usr/local/bin/myfile.old /somewhere/else'} <mike -- Mike Meyer <mwm@mired.org> http://www.mired.org/home/mwm/ Q: How do you make the gods laugh? A: Tell them your plans. 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?15287.35274.798595.307311>