Bash - Clearing the last output correctly
问题 I'm trying to create an update-able progress status. In order to do that, I need to be able to clear the last output in its entirety so that I can update it. Carriage returns can work, but when the output is longer than the terminal width and wraps around, it will fail to clear the last output. So I'm using tput: n=0 while [[ $n -ne 100 ]]; do n=$((n+1)) tput ed #clear tput sc #save cursor echo -n "Progress: ${n}%" tput rc #restore cursor sleep 1s done echo But this will fail if the output is