My shell script can't seem to call another script
hi, i'm making a shell script that iteratively checks for duplication of files within a directory...
so, if i have file1.txt, file2.txt and file3.txt, then the script should check file1.txt against file2.txt, file1.txt against file3.txt, file2.txt against file3.txt and so on...
i got two files with me, here the first part
*********************************************************************************************
#duplication.sh
#this file is basically comparing two files given by duplication_loop.sh
#!/bin/sh
num=0
num2=0
num3=0
commnum=0
commnum2=0
commnum3=0
echo Checking $1 against $2...
#Replace the tabs with a single space
tr '\t' ' ' < $1 > temp1.tmp
tr '\t' ' ' < $2 > temp2.tmp
#Remove all trailing white spaces at the end of the lines and convert multiple spaces to a single space
sed -e 's/ *$//' -e 's/ */ /g' temp1.tmp > temp3.tmp
sed -e 's/ *$//' -e 's/ */ /g' temp2.tmp > temp4.tmp
#Remove all the blank lines
grep -v "^$" temp3.tmp > temp5.tmp
grep -v "^$" temp4.tmp > temp6.tmp
while read commline1
do
commnum2=`expr $commnum2 + 1` #Count the number of lines in the first file given
while read commline2
do
if [ "$commline1" = "$commline2" ];then #If the lines matched
commnum=`expr $commnum + 1` #Increment the counter
echo $commnum > commnum.tmp #Save the result of "commnum" to a temporary file or else it'll get re-initiated once it got out of the loop
fi
done < temp6.tmp
#Save the result of "commnum2" to a temporary file or else it'll get re-initiated once it got out of the loop
echo $commnum2 > commnum2.tmp
#Retrieve the "commnum" value
commnum=`cat commnum.tmp`
done < temp5.tmp
#Remove the comments
sed -e 's;#.*;;' -e '/^[ ]*$/d' temp5.tmp > temp7.tmp
sed -e 's;#.*;;' -e '/^[ ]*$/d' temp6.tmp > temp8.tmp
while read line1
do
num2=`expr $num2 + 1` #Count the number of lines in the first file given
while read line2
do
if [ "$line1" = "$line2" ];then #If the lines matched,
num=`expr $num + 1` #Increment the counter
echo $num > num1.tmp #Save the result of "num" to a temporary file or else it'll get re-initiated once it got out of the loop
fi
done < temp8.tmp
#Save the result of "num2" to a temporary file or else it'll get re-initiated once it got out of the loop
echo $num2 > num2.tmp
#Retrieve the "num" value
num=`cat num1.tmp`
done < temp7.tmp
commnum=`cat commnum.tmp`
commnum2=`cat commnum2.tmp`
num=`cat num1.tmp`
num2=`cat num2.tmp`
num3=`expr $num2 - $num` #Calculate the number of lines not matched
perc=`expr $num3 \* 100`
perc=`expr $perc / $num2`
commnum3=`expr $commnum2 - $commnum` #Calculate the number of comments not matched
commperc=`expr $commnum3 \* 100`
commperc=`expr $commperc / $commnum2`
echo Total lines matched $commnum
echo total lines not matched $commnum3
echo Percentage of total lines different $commperc\%
echo Total lines matched excluding comments $num
echo Total lines not matched excluding comments $num3
echo Percentage of total lines different excluding comments $perc\%
rm -f *.tmp
************************************************************************************************
and here's the second file
************************************************************************************************
#duplication_loop.sh
#this file iterates through the directory to compare files against each other
#!/bin/sh
i=1
j=1
ls > ltemp.rbs
no_lines=`cat ltemp.rbs | wc -l`
while [ $i -lt $no_lines ]
do
fname1=`cat ltemp.rbs | sed -n "${i}p"`
while [ $j -lt $no_lines ]
do
if [ $i -eq $j ];then
j=`expr $j + 1`
continue
else
fname2=`cat ltemp.rbs | sed -n "${j}p"`
./duplication.sh $fname1 $fname2
j=`expr $j + 1`
fi
done
i=`expr $i + 1`
done
rm -f *.rbs
*************************************************************************************************
the problem is, it's fine when i call the duplication as ./duplication.sh file1.txt file2.txt
it works fantastically
but when i call ./duplication_loop.sh, it gives me some problem that i cannot understand... somehow it cannot create the temp files.... or maybe it got deleted right after the creation...
to understand the problem more, please but and paste it to your editor and run it yourself... the filenames are duplication_loop.sh and duplication.sh
PLEASE HELP!!!!!!!! thank you so much
|