如何添加一个进度条到一个shell脚本? [英] How to add a progress bar to a shell script?
本文介绍了如何添加一个进度条到一个shell脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当脚本在bash或* NIX任何其他外壳,运行一个命令而将超过几秒钟,就需要一个进度条。
When scripting in bash or any other shell in *NIX, while running a command that will take more than a few seconds, a progress bar is needed.
例如,复制大文件时,打开一个大的tar文件。
For example, copying a big file, opening a big tar file.
你推荐什么方式来添加进度条shell脚本?
What ways do you recommend to add progress bars to shell scripts?
推荐答案
您可以通过覆盖线实现这一点。使用 \\ r
来回到行的开头,而无需编写 \\ n
终端。
You can implement this by overwriting a line. Use \r
to go back to the beginning of the line without writing \n
to the terminal.
写 \\ n
当你完成前进就行了。
Write \n
when you're done to advance the line.
使用回声-ne
来:
- 无法打印
\\ n
和 - 要承认逃跑\\ r 如
序列。
下面是一个演示:
echo -ne '##### (33%)\r'
sleep 1
echo -ne '############# (66%)\r'
sleep 1
echo -ne '####################### (100%)\r'
echo -ne '\n'
这篇关于如何添加一个进度条到一个shell脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文