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?
It's not necessary to use seq in Bash:
for x in {1..10}
do
dosomething
done
Let's say you want to clear 10 lines starting at the 8th line on the screen, you can use tput to move the cursor and do the clearing:
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
See man 5 terminfo for more information.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With