Find the answer to your Linux question:
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 ...
  1. #1
    Just 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.

  2. #2
    Just 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

  3. #3
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    Where to start?

    In the long run (and possibly even in the short run), you would do well to start by googling this:
    Code:
    bash tutorial
    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.
    --
    Bill

    Old age and treachery will overcome youth and skill.

  4. #4
    scm
    scm is offline
    Linux 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!

  5. #5
    Linux 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.

  6. #6
    Just 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...

  7. #7
    Linux Enthusiast apoorv_khurasia's Avatar
    Join Date
    Feb 2005
    Location
    Laurasia
    Posts
    624
    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).
    "There is no sixth rule"
    --Rob Pike
    Registered Linux User: 400426 home page

  8. #8
    Just Joined!
    Join Date
    Nov 2007
    Location
    Camp Pendleton
    Posts
    55
    That's cool, because I have nightmares about trying to debug existing perl scripts.

  9. #9
    Linux Enthusiast apoorv_khurasia's Avatar
    Join Date
    Feb 2005
    Location
    Laurasia
    Posts
    624
    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.
    "There is no sixth rule"
    --Rob Pike
    Registered Linux User: 400426 home page

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...