gpt4 book ai didi

bash - bash 中的状态栏

转载 作者:行者123 更新时间:2023-11-29 09:18:42 30 4
gpt4 key购买 nike

首先感谢大家的帮助。我可以在几天内看到我的项目成功完成..

我需要知道如何在 Shell 脚本中放置一个状态栏,类似这样。

No_of_files=55
index=0

while [ $index -lt $No_of_files ]
do
echo -en "$index of $No_of_Files Completed"
index=$((index + 1))
done

预期结果:55 件中的 1 件已完成55 个中的 2 个已完成

每次迭代,应该替换索引而不是其他字符。

谢谢基兰

最佳答案

您可以打印 \r 回到行首,这样您就可以用新消息覆盖最后打印的内容:

for (( I=0 ; I < 10 ; I++ )); do
echo -en "\r$I of 10 completed"
sleep 1
done
echo

看起来只有 $I 数字会发生变化。

关于bash - bash 中的状态栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2324812/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com