我在/root/xml-test/
中有一个目录,其中包含.xml
文件,每个文件为99MB。
我正在使用if TEST
语句检查大小是否大于$a
。
问题是... if语句始终导致A大于B-即使我为A选择了一个较小的数字-如1。
这里是测试自己的脚本。注释中有一个URL,可以为您的测试创建任何大小的文件。
#!/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;
在@ gordon-davisson的帮助下,该问题的解决方案正在更改以下内容:
if [ $a > $b ];
if [ $a \> $b ];
A现在大于B
B可以大于A
很棒!