How to display and refresh multiple lines in bash

后端 未结 5 803
孤独总比滥情好
孤独总比滥情好 2020-12-14 21:49

I am writing a installation script and would like to display the status of the script as it progresses.

example:

var1=\"pending\"
var2=\"pending\"
va         


        
5条回答
  •  清歌不尽
    2020-12-14 22:17

    You can use the carriage return to change text on a single status line.

    n=0
    while true; do
      echo -n -e "n: $n\r"
      sleep 1
      n=$((n+1))
    done
    

    If you can put all your counters on one line

    n=0
    m=100
    while true; do
      echo -n -e "n: $n  m: $m\r"
      sleep 1
      n=$((n+1))
      m=$((m-1))
    done
    

    This technique doesn't seem to scale to multiple lines, though it does have the benefit over tput that it works on dumb terminals (like Emacs shell).

提交回复
热议问题