From owner-freebsd-questions Sun Sep 30 14: 8:32 2001 Delivered-To: freebsd-questions@freebsd.org Received: from guru.mired.org (okc-94-248-46.mmcable.com [24.94.248.46]) by hub.freebsd.org (Postfix) with SMTP id 259A237B40D for ; Sun, 30 Sep 2001 14:08:28 -0700 (PDT) Received: (qmail 56334 invoked by uid 100); 30 Sep 2001 21:08:26 -0000 From: Mike Meyer MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <15287.35274.798595.307311@guru.mired.org> Date: Sun, 30 Sep 2001 16:08:26 -0500 To: jacks@sage-american.com Cc: questions@freebsd.org Subject: Re: Scripting question In-Reply-To: <72642935@toto.iv> X-Mailer: VM 6.90 under 21.1 (patch 14) "Cuyahoga Valley" XEmacs Lucid X-face: "5Mnwy%?j>IIV\)A=):rjWL~NB2aH[}Yq8Z=u~vJ`"(,&SiLvbbz2W`;h9L,Yg`+vb1>RG% *h+%X^n0EZd>TM8_IB;a8F?(Fb"lw'IgCoyM.[Lg#r\ 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 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'} 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