try replacing clear
with tput clear
or printf '\33[H\33[J'
. clear
(to clear the screen), though common is not a standard command.
tput clear
and printf
are standard, the escape sequence to clear the screen may vary from terminal to terminal, tput clear
would query the termcap or terminfo databases for the sequence for the terminal specified with the $TERM
environment variable; with printf
, here we hard code the sequence for DEC terminals (starting with the VT100 terminal from the late 70s) and as specified by ANSI X3.64 where \33[H
takes the cursor to the home position, and \33[J
clears til the end of the screen (leaving scrollback buffer and alternate screen, where supported, alone) which is recognised by most terminals and terminal emulators.
clear
withtput clear
orprintf '\33[H\33[2J'
.clear
(to clear the screen), though common is not a standard command.