Hello,
I have a directory in /root/xml-test/ which contains .xml files and they are 99MB each. I'm using an if TEST statement to check if the size is larger than $a.
The problem is... the if statement always results in the A, larger than B - even if I choose a small number for A - such as 1.
here is the script and test yourself. There is a URL in the comments to create a file of anysize for your testing.
#!/bin/bash
#This will check the size of the XML files in /root/xml-test
# Script Test Procedures
# Create file of any size
#https://www.ostechnix.com/create-files-certain-size-linux/
xmlpath='/root/xml-test/.'
size=$(find $xmlpath -type f -name '*.xml' -exec du -c {} + | grep total$) ; total=$(echo $size | cut -c 1- | rev | cut -c 7- | rev)
b=$total
echo $total 'size in bytes' && echo "enter a second number";'
read a ;
echo "a=$a";
echo b=$total;
if [ $a > $b ];
then
echo "a is greater than b";
else
echo "b is greater than a";
fi;
Aucun commentaire:
Enregistrer un commentaire