我正在编写一个用于处理文件夹的小脚本。
由于运行时间相当长,因此我想添加一个进度条。
以下是迭代过程:
for file in */
do
#processing here, dummy code
sleep 1
done
拥有计数器并知道文件夹数量是一种解决方案。 但我正在寻找更通用和更短的解决方案...
我希望有人能有一个想法。 谢谢你的关注,
朱利安
编辑:
我得到了这个解决方案,它可以做到我想要的,并且非常具有图形化:
#!/bin/bash
n_item=$(find /* -maxdepth 0 | wc -l)
i=0
for file in /*
do
sleep 1 #process file
i=$((i+1))
echo $((100 * i / n_item)) | dialog --gauge "Processing $n_item folders, the current is $file..." 10 70 0
done
然而,我将保留fedorqui的解决方案,该方案不会占用整个屏幕。
非常感谢您的时间。