有没有比echo""擦除一条线更好的方法?

Bre*_*nt 2 bash

我想用bash擦除屏幕上的几行(比方说10行).

我知道这可以通过以下方式完成:

for x in `seq 1 10`; do
  echo "                                                    "
done
Run Code Online (Sandbox Code Playgroud)

但必须有一个更好的方法.

就像是:

echo -n10 --blank
Run Code Online (Sandbox Code Playgroud)

要么

echo -n10 space(80)
Run Code Online (Sandbox Code Playgroud)

或类似的东西.

有任何想法吗?

Pau*_*ce. 5

没有必要seq在Bash中使用:

for x in {1..10}
do
    dosomething
done
Run Code Online (Sandbox Code Playgroud)

假设您要从屏幕的第8行开始清除10行,您可以使用tput移动光标并进行清除:

tput cup 8 0        # move the cursor to line 8, column 0
for x in {1..10}
do
    tput el          # clear to the end of the line
    tput cud1        # move the cursor down
done
tput cup 8 0        # go back to line 8 ready to output something there
Run Code Online (Sandbox Code Playgroud)

有关man 5 terminfo更多信息,请参阅