我正在尝试设置 bash 脚本,以便将文件从一个目录移动到指定的大小限制(在本例中为 1GB)。我试图让它进入循环,但我遇到了 while 语句的问题。它不断返回以下输出,我不知道为什么。如果我尝试在 while bash 中使用 "$currentSize" 表示它期望进行整数比较。但是 bash 中的变量应该是无类型的,所以我不能将它转换为整数,对吧?任何帮助都是适当的。
输出
54585096
1048576
./dbsFill.bsh: line 9: [: -lt: unary operator expected
代码
#!/bin/bash
currentSize= du -s /root/Dropbox | cut -f 1
maxFillSize=1048576
echo $currentSize
echo $maxFillSize
cd /srv/fs/toSort/sortBackup
while [ $currentSize -lt $maxFillSize ]
do
#fileToMove= ls -1
#rsync -barv --remove-source-files $fileToMove /root/Dropbox/sortme
# mv -t /root/Dropbox/sortme $(ls -1 | head -n 1)
#find . -type f -exec mv -t /root/Dropbox/sortme {} \;
#currentSize= du -s /root/Dropbox | cut -f 1
# sleep 5
echo Were are here
done