本文介绍了bash脚本,删除previous行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在许多Linux程序,如卷曲,wget的,和任何一个进度表,他们的底线不断更新,每隔一定的时间。我该怎么做,在bash脚本?所有我现在能做的也只是呼应了新的路线,这不是我想要的,因为它建立起来。我也遇到过,所提到tput的杯0 0的东西,但我尝试过了,它是一种古怪。什么是最好的方法是什么?


解决方案

  {
  在$ PC(SEQ 1 100);做
    回声-ne$ PC%\\ 033 [0K \\ R
    usleep 100000
  DONE
  回声
}

在\\ 033 [0K将删除该行的末尾 - 的情况下,你的进步得到线在某些时候更短,虽然这可能无法满足您的需要。

的为\\ r,将光标移动到当前行的开头

回声的-n将prevent光标前进到下一行

In lots of Linux programs, like curl, wget, and anything with a progress meter, they have the bottom line constantly update, every certain amount of time. How do I do that in a bash script? All I can do now is just echo a new line, and that's not what I want because it builds up. I did come across something that mentioned "tput cup 0 0", but I tried it and it's kind of quirky. What's the best way?

解决方案
{
  for pc in $(seq 1 100); do
    echo -ne "$pc%\033[0K\r"
    usleep 100000
  done
  echo
}

The "\033[0K" will delete to the end of the line - in case your progress line gets shorter at some point, although this may not be necessary for your purposes.

The "\r" will move the cursor to the beginning of the current line

The -n on echo will prevent the cursor advancing to the next line

这篇关于bash脚本,删除previous行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 00:44