Find the answer to your Linux question:
Results 1 to 4 of 4
I'm having problems getting a C Shell script to work. The script is supposed to take all the files in a directory and transfer them to another directory. Simple enough, ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Ice
    Ice is offline
    Just Joined!
    Join Date
    Mar 2003
    Location
    Auburn, AL
    Posts
    20

    C Shell problems


    I'm having problems getting a C Shell script to work. The script is supposed to take all the files in a directory and transfer them to another directory. Simple enough, right? Well, when I execute the script, it just acts like the copy command isn't even there. When I use that very same command at the prompt, it works perfectly. Is there anything I need to put in the script besides the copy command to make this work? Any help is much appreciated...

  2. #2
    Linux Engineer
    Join Date
    Jan 2003
    Location
    Lebanon, pa
    Posts
    994
    A C shell script? Do you mean bash? Anyway paste your script. Just a thought but you might have to set the patch to cp in the script before executing it.

  3. #3
    Linux Engineer
    Join Date
    Apr 2003
    Location
    Sweden
    Posts
    796
    Something like this maybe..

    Code:
    #!/bin/sh
    
    # Directory where your files are located
    FILEDIR=/tmp/filedir
    
    # Directory to where the files should be copied.
    DESTDIR=/tmp/otherdir
    
    
    if [ -d $FILEDIR ]
       then
       cd $FILEDIR
       FILES=`find . -type f`
    else
       echo "Filedir:$FILEDIR doesnt exist"
        exit 1
    fi
    
    for i in $FILES
         do
          echo "Copying $i to $DESTDIR"
          cp $i $DESTDIR
    
          if [ $? = 0 ]
             then
             echo "Succeeded"
          else
             echo "Copy failed"
             exit 1
         fi
    done
    Regards

    Andutt

  4. #4
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    Or maybe:
    Code:
    cp -R /tmp/filedir/* /tmp/otherdir

Posting Permissions

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