#!/bin/sh
#] 
#] *********************
#] $ bash  "$d_bin"'dir_size sum, net.sh'  - 
# www.BillHowell.ca  05Aug2018 initial

# to run  $ bash "$d_bin"'dir_size sum, net.sh'  "$f_du_data"  "$f_duSizes"  "$f_duNetSz"
#    example see "$d_bin"'backupper/backup.sh'


f_du_data="$1"
f_duSizes="$2"
f_duNetSz="$3"

cat  "$f_du_data"  |  grep  --only-matching "^[0-9]*"  >"$f_duSizes"

exec 9<"$f_duSizes"

read -u 9 line  

let "total = line"
let "residual = line"
#echo  "total=  $total" 


#] calculations()  - 

	calculations()
{
while read -u 9 line; do
   let "residual = residual - line"
#   echo  "residual=  $residual" 
done 
percent=$(echo "scale=2; $residual/$total*100"  |  bc)
}  


calculations

echo  >"$f_duNetSz"  ""
echo  >"$f_duNetSz"  "total(Mb)=  $total, excludes=$excludes, residual(Mb)= $residual, residual(%)= $percent" 


# Example : 
# generate "dir_size list.txt" with : 
# $  du  --block-size=M  --max-depth=0  "/media/bill/PROJECTS"   >"/media/bill/ramdisk/dir_size list.txt"
# $  du  --block-size=M  --max-depth=1  "/media/bill/PROJECTS"  >>"/media/bill/ramdisk/dir_size list.txt"
# delete the last row of "/media/bill/ramdisk/dir_size list.txt"
# $  bash   "/media/bill/SWAPPER/bin/dir_size sum, net.sh"  "/media/bill/ramdisk/dir_size list.txt"  "/media/bill/ramdisk/dir_size sizes.txt"  "/media/bill/ramdisk/dir_size sum, net.txt"

# https://linuxhint.com/bash_arithmetic_operations/
# One of the limitations of bash is that it can’t handle floating point or double numbers like other scripting languages. Another command tool is used in bash to solve this problem.
# let - 
# Example – 3: Using double brackets
# Example – 4: Using ‘bc’ command for float or double numbers 
#!/bin/bash
# Dividing 55 by 3 with bc only
# echo "55/3" | bc
# Dividing 55 by 3 with bc and -l option
# echo "55/3" | bc -l
# Dividing 55 by 3 with bc and scale value
# echo "scale=2; 55/3" | bc




# enddoc
