Assuming that the clear
really clears the screen, then the script shown, by itself, will not produce the first screenshot. If you had an additional process which is appending to /tmp/temp_script.log
, then that could do something...
On the other hand, if your terminal is not clearing the screen, that's part of the problem. Perhaps that colored line is the prompt from which you ran the script, and you could like to keep that at the top of the screen:
- normally you would set
TERM
to a suitable value which corresponds to a terminal description.
- a "suitable" terminal description tells how to clear the screen.
- as a side effect, clearing the screen (by convention) also moves the cursor to the upper-left corner of the screen, but
- clearing the screen from the upper-left corner of the screen would also clear the colored line (which you might want to keep)
- if you wanted to clear from the second line, you could (on most terminals) do
printf '\033[2H\033[J'
or
tput cup 1 0
tput ed
- but keep in mind that if your prompt was originally not at the top of the screen, this would just leave whatever was at the top of the screen untouched.
The other part of the problem is that the three lines are printed repeatedly, going down the screen. You could change that to move the cursor where you want to print the counter, e.g.,
printf '\033[4H'
or
tput cup 3 0
Putting those together, your script might look like this (and using printf
, since something seems amiss with your TERM
and/or terminal description):
#!/bin/bash
if [ -t 0 ]; then stty -echo -icanon -icrnl time 0 min 0; fi
#result=`sensors -A`
count=0
printf '\033[2H\033[J'
keypress=''
echo "linha 1"
echo "Linha 2
while [ "x$keypress" = "x" ]; do
let "count++"
printf '\033[4H'
echo $count
sleep 1
keypress="`cat -v`"
done
if [ -t 0 ]; then stty sane; fi
exit 0
Further reading: