本文介绍了如何在bash中显示和刷新多行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在编写安装脚本,并希望在脚本进行时显示其状态.
I am writing a installation script and would like to display the status of the script as it progresses.
示例:
var1="pending"
var2="pending"
var3="pending"
print_status () {
echo "Status of Item 1 is: "$var1""
echo "Status of Item 2 is: "$var2""
echo "Status of Item 3 is: "$var3""
}
code that does something and then refreshes the
output above as the status of each variable changes.
推荐答案
此代码应为您提供想法:
This code should give you the idea:
while :; do
echo "$RANDOM"
echo "$RANDOM"
echo "$RANDOM"
sleep 0.2
tput cuu1 # move cursor up by one line
tput el # clear the line
tput cuu1
tput el
tput cuu1
tput el
done
使用man tput
了解更多信息.要查看功能列表,请使用man terminfo
Use man tput
for more info. To see the list of capabilities use man terminfo
这篇关于如何在bash中显示和刷新多行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!