wellster34
Programmer
Hi,
I know very little about Unix and was given a script which is giving me trouble. I need help in understanding what is going on in this piece of Unix script. It is a Korn shell script.
for f in sourcename.txt
do
if [ "$f" = "sourcename.txt" ]; then
echo "****************************************************"
echo "* No files found to build data file. *"
echo "****************************************************"
rm -f targetname.txt
exit 1
else
echo " Appending file $f to targetname.txt."
RC0=`cat $f >> targetname.txt`
RCANS0="$?"
if [ $RCANS0 -eq 0 ]; then
echo " Deleting file $f."
RC1=`rm -f $f `
RCANS1="$?"
if [ $RCANS1 -eq 0 ]; then
echo " "
else
#
# Indicate the delete file process completed unsuccessfully.
#
echo " "
echo "***********************************************"
echo "* Could not delete the datetime stamped file. *"
echo "***********************************************"
echo " "
echo " --> Finished FTP process unsuccessfully."
echo " --> End of Step 02 "
exit 1
fi
else
#
# Indicate the append file process completed unsuccessfully.
#
echo " "
echo "***********************************************"
echo "* Could not append the datetime stamped file. *"
echo "***********************************************"
echo " "
echo " --> Finished FTP process unsuccessfully."
echo " --> End of Step 02 "
exit 1
fi
fi
done
I need help in understanding the for do loop. Can someone explain what is going on above in the code?
Anything at all will be greatly appreicated!
Thanks,
Josh
I know very little about Unix and was given a script which is giving me trouble. I need help in understanding what is going on in this piece of Unix script. It is a Korn shell script.
for f in sourcename.txt
do
if [ "$f" = "sourcename.txt" ]; then
echo "****************************************************"
echo "* No files found to build data file. *"
echo "****************************************************"
rm -f targetname.txt
exit 1
else
echo " Appending file $f to targetname.txt."
RC0=`cat $f >> targetname.txt`
RCANS0="$?"
if [ $RCANS0 -eq 0 ]; then
echo " Deleting file $f."
RC1=`rm -f $f `
RCANS1="$?"
if [ $RCANS1 -eq 0 ]; then
echo " "
else
#
# Indicate the delete file process completed unsuccessfully.
#
echo " "
echo "***********************************************"
echo "* Could not delete the datetime stamped file. *"
echo "***********************************************"
echo " "
echo " --> Finished FTP process unsuccessfully."
echo " --> End of Step 02 "
exit 1
fi
else
#
# Indicate the append file process completed unsuccessfully.
#
echo " "
echo "***********************************************"
echo "* Could not append the datetime stamped file. *"
echo "***********************************************"
echo " "
echo " --> Finished FTP process unsuccessfully."
echo " --> End of Step 02 "
exit 1
fi
fi
done
I need help in understanding the for do loop. Can someone explain what is going on above in the code?
Anything at all will be greatly appreicated!
Thanks,
Josh