Error Handling

Helo Experts,
I need a help in handling errors in shell script, wants my errors displayed in text file instead of command window..
My shell script is here;

cd /cygdrive/s/Files
for FILES in ./*.*
do
temp=`basename $FILES`

if cp $FILES /cygdrive/r/CopyFile1/$FILES; then
echo "copy successful"
echo "$temp ">> /cygdrive/r/LogFiles/logfiles.rtf

else
echo "copy failed"	
fi

done

By doin if..else i can manage to output copy successful or failes..but i receive error thrown during cp $FILES /cygdrive/r/CopyFile1/$FILES.
That error is displayed in command wondow ( im using cygwin).
Anyone can guide me on how can i handle that error where the error should be in text file (error.txt) and my output only shows copy failed or successful

your help is much appreciated

cd /cygdrive/s/Files
for FILES in ./*.*
do
   temp=`basename $FILES`

   if cp $FILES /cygdrive/r/CopyFile1/$FILES 2>error.txt ; then
      echo "copy successful"
      echo "$temp ">> /cygdrive/r/LogFiles/logfiles.rtf

   else
      echo "copy failed"
   fi
done

Jean-Pierre.

Thanks for quick reply

what the 2>error.txt for?
y 2??

0 = Standard Input
1 = Standard Output
2 = Standard Error

the 2>error.txt would redirect all output from standard errors, into a file called error.txt

There are three standard sources of input and output for a program. Standard input usually comes from the keyboard if it�s an interactive program, or from another program if it�s processing the other program�s output. The program usually prints to standard output, and sometimes prints to standard error. These three file descriptors called STDIN (0), STDOUT (1), and STDERR (2).

Thanks for help guys :slight_smile:
U r really great