Results 1 to 9 of 9
i'm supposed to make a script that allows users to back up any number of files/filesets. the files are input to the script as command line parameters. the first parameter ...
- 11-23-2007 #1Just Joined!
- Join Date
- Nov 2007
- Posts
- 5
New to shell scripting and I'm not sure where to start.
i'm supposed to make a script that allows users to back up any number of files/filesets. the files are input to the script as command line parameters. the first parameter represents the directory path which the files are to be copied and the remaining parameters represent the file/filesets paths that you want to copy.
syntax for running the script:
./bkup <dirname> <file path> <file path> ...
i just need a boost and i think i'll be able to figure out everything else. like i said, i just don't know where to start. what's throwing me off is how the files are input to the script as command line parameters. not sure what to do.
if someone could help me that would be really appreciated.
- 11-23-2007 #2Just Joined!
- Join Date
- Nov 2007
- Location
- Camp Pendleton
- Posts
- 55
Arguments to scripts are really easy. They're named $1, $2, etc. See:
Code:$ cat bkup.sh #!/bin/bash echo "param 1: $1" echo "param 2: $2" $ ./bkup.sh asdf fdsa param 1: asdf param 2: fdsa
- 11-23-2007 #3
Where to start?
In the long run (and possibly even in the short run), you would do well to start by googling this:
You will quickly find out the answer to your current question, and be on the way to learning enough not to walk down too many blind alleys.Code:bash tutorial
--
Bill
Old age and treachery will overcome youth and skill.
- 11-24-2007 #4Linux Engineer
- Join Date
- Feb 2005
- Posts
- 1,044
It's also good to read other people's scripts to see what sort of constructs and techniques are used (and to understand them!) - I'm still learning after nearly 30 years of scripting!
- 11-24-2007 #5Linux Enthusiast
- Join Date
- Aug 2006
- Location
- Portsmouth, UK
- Posts
- 539
Great comment on learning about scripting.
If you script is to backup files, why not use tar ?RHCE #100-015-395
Please don't PM me with questions as no reply may offend, that's what the forums are for.
- 11-24-2007 #6Just Joined!
- Join Date
- Nov 2007
- Location
- Camp Pendleton
- Posts
- 55
Actually, for a scripting guide, I think this rocks:
Bash by example, Part 1
It's a three part series. The other parts start getting more advanced quickly, but the author keeps it easy to understand...
- 11-27-2007 #7
As far as understanding what someone else's script does is here is what I have to say: been scripting for about 4 years now and still get nightmares about understanding an existing shell script.
My personal affection has been Perl (in the scripting world that is).
- 11-27-2007 #8Just Joined!
- Join Date
- Nov 2007
- Location
- Camp Pendleton
- Posts
- 55
That's cool, because I have nightmares about trying to debug existing perl scripts.
- 11-27-2007 #9
The problem is with idioms you see. People have a particular way of doing things in Perl and since there is usually more than one way to do things in Perl it gets messy.


Reply With Quote