Scripting change of text in another file

Hello, I am pretty new to UNIX/bash scripting, so this question may seem obvious. My experience is simply stringing commands together in a script, maybe doing some if/then testing and such, so I haven't gotten into anything too heavy...

I have a shell script that I use as a template to create backup scripts for certain directories. These scripts are essentially the same, with the exception of the value of some variables. Other than that, they are identical. So, it is easy enough to simply make copies of this template, then manually go in and change the variable names (I make separate scripts for each directory, as some are deemed more important, so I want them backed up via cron more frequently). To make the copies, I have simply done:

for copy in dir1 dir2 dir3; do
cp template.sh $copy.sh
done

It is crude yes, but like I said, I am inexperienced (I'm trying though!). I was wondering what I would need in order to change the variable values as well, so I can script it all. That way, I could edit the template file, then run one script and it would produce the copies and change their variable values. I have done some reading on 'awk' and 'sed', but am not sure which I need (or if I need both)

Just a nudge is all I need... No need to do it for me! Thanks for any insight.

Wouldn't it be easier to make the generic backup script ("template") accept parameters, then call the very same script at different times with different parameters, approximately ...

Cron tab

00 21 * * *  sh backup.sh dir1
00 22 * * *  sh backup.sh dir2
00 23 * * *  sh backup.sh dir3

Shell script

SOURCE="$1"
# [code here]

Wow, that would be SO much easier. I had no idea that you could do that (I told you I was a rookie!). So, is it possible to use more that one argument? I would think so, just looking at some other commands I have used with many arguments, but...

Sure. Parameter 1 is $1, 2 is $2, and so forth. $# is the number of parameters available. The 'shift' command makes it easy to put it in a loop by getting rid of the first parameter and moving them all down. This would print all parameters, first to last:

while [ "$#" -gt 0 ]
do
        echo "Parameter is $1"
        shift
done

Parameters in functions work the exact same way as parameters on the command-line.

Awesome. So I can essentially, write one script, only changing the arguments in the crontab, and all will be well. I am going to love the simplicity in this. Thanks for the help!

Hello again, I am visiting this again, after running into a tiny snag... When using the directory as an argument in the crontab, it behaves completely erratically if the argument has a space in the name (which makes sense as instead of both words being used as an argument, one is being used as the first argument and the other is being used as the second).
I have tried using "misc info", 'misc info', misc\ info, and none seem to work. Should I enclose the name in {} or []? Maybe combine using quotes and escaping the space with a \?

Just to clarify...

My crontab looks vaguely like this:

x x x x x /path/to/script.sh Misc Info enc

So, the script is looking for two arguments, but seeing three (Misc, Info, and enc). I have been trying all sorts of crazy combinations to get Misc Info recognized as one argument with no luck...

Enclosing both the argument and it's "interpretation" with single and double quotes, respectively, should do the trick - approximately (no Penguin within reach to ask for confirmation, sorry ...):

Script Call

sh backup.sh 'dir1'

Script Code

SOURCE="$1"

Got it! Thanks again, Dr. House. When I was trying to figure this out, I would always include one in quotes, but not the other, so I could never get it to work. I did have to tweak it a bit, because my rookie scripting does things that probably should not be done... I had one variable inside of another.
So, I had:

Variable1=$1
Variable2=xxxx.$1.xxxx

In addition to putting the argument in Cron in quotes, and adding the $1 in quotes, I also had to go through the script, and every occurrence of Variable2 had to be put in quotes. I couldn't see it by looking at it, and being new enough that I didn't understand BASH variable expansion and such, but I kind of just stumbled on it by looking at the files that the script was creating, and wondering why I had two log files ('mediaserver.Bill' and 'Info.remotebackup.errors.txt') instead of one long-filenamed error log.
Thanks for the push in the right direction!