Arguements with a shell script

This is a discussion on Arguements with a shell script within the Linux Programming forums, part of the Platform Specific Boards category; I have to write a shell script that copies all files in the directory subtree and output the files into ...

  1. #1
    Doh
    Doh is offline
    Registered User
    Join Date
    Nov 2002
    Posts
    5

    Arguements with a shell script

    I have to write a shell script that copies all files in the directory subtree and output the files into one file, and all directories into another file.

    The arguement passed is the directory my script should start in. I have this, but don't know how to set the arguement and make the script not crash. I know the arguement is stored in '$1' but I dunno where to add "cd $1" or something in this code.

    Code:
    #!/bin/sh
    for i in *; do
            if test -f $i; then
            echo `pwd`/$i >> /gaul/s1/student/2001/rgallard/outfiles.txt
    fi
    done
    for k in *; do
            if test -d $k; then
    
            echo `pwd`/$k >> /gaul/s1/student/2001/rgallard/outdirs.txt
            cd $k
    
            /gaul/s1/student/2001/rgallard/prt4.sh
            cd ..
    
            fi
            done

  2. #2
    Unreg
    Guest
    Lookup the find command, and let that do the work for you.

    EG

    To print all directories under root:

    find / -type d

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. using tar command in a shell script
    By rohan_ak1 in forum Linux Programming
    Replies: 1
    Last Post: 05-10-2008, 07:03 AM
  2. shell script basic question
    By PedroTuga in forum Linux Programming
    Replies: 1
    Last Post: 09-09-2006, 03:24 AM
  3. invoking shell script
    By agoel01 in forum C Programming
    Replies: 1
    Last Post: 12-01-2005, 10:37 AM
  4. Game structure, any thoughts?
    By Vorok in forum Game Programming
    Replies: 2
    Last Post: 06-07-2003, 01:47 PM
  5. Running 'exec' twice in one UNIX shell script
    By Zughiaq in forum Tech Board
    Replies: 2
    Last Post: 05-03-2003, 12:04 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21