I have the following code to get the percentage of values
output(){
echo location of the saved outputs from diff.sh $outputDirectory
#for echoing the no of lines changed-------------------------------------
noChanges=$(cat "$outputDirectory"/diffChanges.txt | wc -l)
echo "no of lines changed" $noChanges
#for echoing the no of lines added--------------------------------------
#no of lines directly added to the repo
noAdditions=$(cat "$outputDirectory"/diffAdditions.txt | wc -l)
echo "no of lines added" $noAdditions
#for echoing the no of lines deleted------------------------------------
noDeletions=$(cat "$outputDirectory"/diffDeletions.txt | wc -l)
echo "no of lines deleted" $noDeletions
#Counting the total no of lines in the repo-----------------------------------------------------------------
totalNoOfLinesInTheRepo=$(git -C "$repoLocation" diff --shortstat $(git -C "$repoLocation" hash-object -t tree /dev/null) | cut -d " " -f5)
echo total no of lines in the repo $totalNoOfLinesInTheRepo
noLines=$totalNoOfLinesInTheRepo
#totalNoOfLinesInTheRepo=1000
#calcutlating percentages of line changes----------------------------------------------------------------------------
changesPercentage=$(awk "BEGIN { cp=100*${noChanges}/${noLines}; i=int(cp); print (cp-i<0.5)?i:i+1 }")
dditionPercentage=$( awk "BEGIN {ap=100*${noAdditions}/${totalNoOfLinesInTheRepo};j=int(ap);print (ap-j<0.5)? j:j+1 }")
deletionPercentage=$( awk "BEGIN {dp=100*${noDeletions}/${totalNoOfLinesInTheRepo};k=int(dp);print (dp-k<0.5)? k:k+1}")
echo "percentage of lines changes"
echo percentage of changed lines $changesPercentage
echo percentage of added lines $additionPercentage
echo percentage of deleted lines $deletionPercentage
}
The out put of this code is
no of lines changed 238
no of lines added 4344
no of lines deleted 971
total no of lines in the repo 425987
percentage of lines changes
percentage of changed lines 0
percentage of added lines 1
percentage of deleted lines 0
Why the calculation is not working. When I assign value to the totalNoOfLinesInTheRepo
directly it gives results, but even if I assigned the value of totalNoOfLinesInTheRepo
to another variable and use it in the calculation ( as in code) it too gives me the above output. What I am doing wrong, please help me to fix this,thanks in advance