bash 中的状态栏

发布于 2024-08-22 22:47:03 字数 334 浏览 4 评论 0原文

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

我需要知道如何在 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

预期结果: 1 / 55 已完成 2 of 55 Completed

每次迭代,索引都应该被替换,但其他字符不能被替换。

谢谢 基兰

Firstly, Thanks everyone for all your help. I can see the successful completion of my project in couple of days..

I need to know how to put a status bar in Shell Script, something like this.

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

Expected Result :
1 of 55 Completed
2 of 55 Completed

Every iteration, index should be replaced but not other characters.

Thanks
Kiran

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

旧夏天 2024-08-29 22:47:03

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

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

这看起来就像是 $I 数字会发生变化。

You can print \r to go back to the beginning of the line, so that you can overwrite the last thing printed with a new message:

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

This looks like the just the $I number would be changing.

眼眸里的那抹悲凉 2024-08-29 22:47:03

您忘记增加 $index 变量。 <代码>((索引++))。您还可以在此处查看用于执行进度条的脚本,

这是一个穷人的版本

No_of_files=55
index=0

while [ $index -lt $No_of_files ]
do
     echo -ne "\r$index of $No_of_files Completed"
     ((index++))
    sleep 1
done

you forgot to increment the $index variable. ((index++)). You can see here also for a script to do progress bar

here's a Poor man's version

No_of_files=55
index=0

while [ $index -lt $No_of_files ]
do
     echo -ne "\r$index of $No_of_files Completed"
     ((index++))
    sleep 1
done
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文