Bash – better way to erase a line than echo ” “

bash

I am wanting to erase several (let's say 10) lines on the screen using bash.

I know this can be done by:

for x in `seq 1 10`; do
  echo "                                                    "
done

but there must be a better way.

Something like:

echo -n10 --blank

or

echo -n10 space(80)

or something similar.

Any ideas?

Best Answer

Try

$ printf "%80s" ""

to get 80 spaces, without a trailing newline. If you want to know how many spaces you need, $COLUMNS is probably want you want:

$ printf "%${COLUMNS}s" ""

will give you a blank line of the appropriate length even if you've resized your window. The "clear" command will clear the entire window, too.